Virtual fields problem

2016-03-10 Thread Sam Clauw
Hi 2 all,

I'm working on my first CakePHP blog project: http://kattenbelletjes.be/
As you can see, there's a footer section that shows the top 25 most popular 
tags.

There are three relevant tables I use the implement those popular tags:

POSTS: id, title, content, slug
TAGS: id, name, slug
POST_TAG_LINK: id, post_id, tag_id

I tried to make a CakePHP query via $this->tag->find, but there was a 
persistent SQL error that I couldn't fix.
So, I tried it on the "$this->tag->query" SQL way:

debug($this->Tag->query(
"SELECT
Tag.name,
COUNT(PostTagLink.id) AS aantal
FROM
tags AS Tag
INNER JOIN
post_tag_links AS PostTagLink
ON
tag.id = PostTagLink.tag_id
WHERE
Tag.show = 'Y'
GROUP BY
Tag.name
ORDER BY
Tag.name ASC"
));

The problem is that the output array isn't very nice:

array(
> (int) 0 => array(
> 'Tag' => array(
> 'name' => 'Beauty'
> ),
> (int) 0 => array(
> 'aantal' => '2'
> )
> ),
> (int) 1 => array(
> 'Tag' => array(
> 'name' => 'Koken'
> ),
> (int) 0 => array(
> 'aantal' => '1'
> )
> ),
> (int) 2 => array(
> 'Tag' => array(
> 'name' => 'Lente'
> ),
> (int) 0 => array(
> 'aantal' => '2'
> )
> ),
> (int) 3 => array(
> 'Tag' => array(
> 'name' => 'Wonen'
> ),
> (int) 0 => array(
> 'aantal' => '4'
> )
> )
> )


I wan't something like this instead:

array(
> (int) 0 => array(
> 'Tag' => array(
> 'name' => 'Beauty',
> 'count' => '2'
> )
> ),
> (int) 1 => array(
> 'Tag' => array(
> 'name' => 'Koken',
> 'count' => '1'
> )
> ),
> (int) 2 => array(
> 'Tag' => array(
> 'name' => 'Lente',
> 'count' => '2'
> )
> ),
> (int) 3 => array(
> 'Tag' => array(
> 'name' => 'Wonen',
> 'count' => '4'
> )
> )
> )


Is there somebody with a solution on this?
Thanks 4 helping ;) 

-- 
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup

We will soon be closing this Google Group. But don't worry, we have something 
better coming. Stay tuned for an updated from the CakePHP Team soon.

Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


CakePhp 2.x Generate tree for Tree Behavior?

2016-01-10 Thread Sam Clauw
A very simple question: is there a way to get an associative array with 
tree nodes build with CakePHP's Tree Behavior? 
I can only find a method that output an array to use in a dropdown field 
...

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at https://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


CakePHP 2.x Persistent virtual fields problem

2015-11-29 Thread Sam Clauw
I have a brainteaser about virtual fields on associated models. I know it 
has it's limitations as you can read here: 
http://book.cakephp.org/2.0/en/models/virtual-fields.html#limitations-of-virtualfields
. 
But in my specific case, I can't apply the theory of passing the 
virtualField property from one model to another (even when I read this 
topic: 
http://stackoverflow.com/questions/14630819/using-virtual-fields-in-cakephp-2-x
).

I'll try to explane my case as clear as possible.

Database info

I have 3 tables to make a navigation on my website:

*menus*
id
name

*pages*
id
title
content

*menu_page_links*
id
menu_id
page_id
title
lft
rgt
plugin
controller
action

One page can be added to multiple menus, that's why I've made a link table 
(menu_page_links) between menus and pages.

Application info

Menu model

class Menu extends AppModel
{
public $hasMany = array(
'MenuPageLink' => array(
'className' => 'MenuPageLink',
'foreignKey' => 'menu_id'
)
);
}

Page model

class Page extends AppModel
{
public $hasMany = array(
'MenuPageLink' => array(
'className' => 'MenuPageLink',
'foreignKey' => 'page_id'
)
);
}

MenuPageLink model

class MenuPageLink extends AppModel
{
public $belongsTo = array(
'Menu',
'Page'
);

// to calculate the depth of every menu page link

public $virtualFields = array(
'depth' => 'COUNT(MenuPageLink.title) - 1'
);
}

AppController

Now in my application, I want to load a specific menu on every page, e.g. 
the "Primary menu" from the "menus" table.
So in AppController.php, I referred to the tree needed models ("Menu", 
"Page" and "MenuPageLink") as following:

public $uses = array(
'Menu',
'Page',
'MenuPageLink'
);

Then I get my menu pages that belongs to my specific menu with id "2":

$menu = $this->MenuPageLink->find('all', array(
'fields' => array(
'MenuPageLink.id',
'MenuPageLink.title',
'MenuPageLink.plugin',
'MenuPageLink.controller',
'MenuPageLink.action',
'MenuPageLink.depth'
),
'joins' => array(
array(
'table' => $this->MenuPageLink->table,
'alias' => 'Parent',
'type' => 'LEFT',
'conditions' => array(
'MenuPageLink.lft BETWEEN Parent.lft AND Parent.rgt',
'MenuPageLink.menu_id' => 1
)
)
),
'conditions' => array(
'MenuPageLink.menu_id' => 2,
'MenuPageLink.lft >' => 1,
'MenuPageLink.deleted' => null
),
'group' => 'MenuPageLink.id',
'order' => array(
'MenuPageLink.lft ASC'
)
));

This is my result when I debug my $menu variable:

array(
(int) 0 => array( 'MenuPageLink' => array( 'id' => '36', 'title' => 'Home', 
'plugin' => '', 'controller' => 'home', 'action' => 'index', 'depth' => '1' ) ),
(int) 1 => array( 'MenuPageLink' => array( 'id' => '39', 'title' => 'News', 
'plugin' => '', 'controller' => 'news_articles', 'action' => 'index', 'depth' 
=> '1' ) ),
(int) 2 => array( 'MenuPageLink' => array( 'id' => '37', 'title' => 'About the 
park', 'plugin' => '', 'controller' => 'pages', 'action' => 'view', 'depth' => 
'1' ) ),
(int) 3 => array( 'MenuPageLink' => array( 'id' => '41', 'title' => 
'Attractions', 'plugin' => '', 'controller' => 'attractions', 'action' => 
'index', 'depth' => '2' ) ),
(int) 4 => array( 'MenuPageLink' => array( 'id' => '42', 'title' => 'Animals', 
'plugin' => '', 'controller' => 'animals', 'action' => 'index', 'depth' => '2' 
) ),
(int) 5 => array( 'MenuPageLink' => array( 'id' => '43', 'title' => 'Events', 
'plugin' => '', 'controller' => 'events', 'action' => 'index', 'depth' => '2' ) 
),
(int) 6 => array( 'MenuPageLink' => array( 'id' => '44', 'title' => 'Shows', 
'plugin' => '', 'controller' => 'shows', 'action' => 'index', 'depth' => '2' ) 
),
(int) 7 => array( 'MenuPageLink' => array( 'id' => '45', 'title' => 'History', 
'plugin' => '', 'controller' => 'pages', 'action' => 'history', 'depth' => '2' 
) ),
(int) 8 => array( 'MenuPageLink' => array( 'id' => '38', 'title' => 'Info', 
'plugin' => '', 'controller' => 'pages', 'action' => 'view2', 'depth' => '1' ) 
),
(int) 9 => array( 'MenuPageLink' => array( 'id' => '40', 'title' => 'Media', 
'plugin' => '', 'controller' => 'pages', 'action' => 'media', 'depth' => '1' ) )
)

So far so good!

What I'm trying

And here comes my problem. I only want to select the pages where *depth = 1*. 
I tried to make a new "conditions" parameter:



$menu = $this->MenuPageLink->find('all', array(
'fields' => array(
'MenuPageLink.id',
'MenuPageLink.title',
'MenuPageLink.plugin',
'MenuPageLink.controller',
'MenuPageLink.action',
'MenuPageLink.depth'
),
'joins' => array(
array(
'table' => $this->MenuPageLink->table,
'alias' => 'Parent',
'type' => 

Re: Plugin appController beforeFilter() action doesn't work anymore

2015-11-28 Thread Sam Clauw
I didn't find out which release changes caused the problem.
But yesterday, I finally got the answar. When I changed  the "beforeFilter" 
tot "beforeRender", it worked again!

Thanks anyway for the help!

Op donderdag 22 oktober 2015 12:13:17 UTC+2 schreef Rob Maurer:
>
> There are changes made with each minor release that can affect your app; 
> start here (http://book.cakephp.org/2.0/en/appendices.html) to see them 
> listed all in one place. - Rob Maurer
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


CakePHP environment plugin doesn't work

2015-11-22 Thread Sam Clauw
I've made a CakePHP application and would like to integrate the 
environments concept. So my app should check the current domain name and 
then automatically determine if the environment is...

 1. Development: http://development.bellewaerdefun.be
 2. Staging: http://staging.bellewaerdefun.be
 3. Production: http://bellewaerdefun.be

After doing that, every environment should have it's own variables set. 
That's perfect to make a database connection without changing the variables 
when the development file is copied to staging and/or production.

So I decided to look for an existing environment plugin and I found this 
one:
https://github.com/josegonzalez/cakephp-environments

I manually copied and installed the needed folder and files, enabled the 
plugin in bootstrap.php and made a configuration file of every environment.

DEVELOPMENT

 array('development.bellewaerdefun.be')
),
array(
// Site specific items

'Settings.FULL_BASE_URL' => 'http://development.bellewaerdefun.be',

'Email.username' => 'em...@example.com',
'Email.password' => 'password',
'Email.test' => 'em...@example.com',
'Email.from' => 'em...@example.com',

'logQueries' => true,

// App Specific functions

'debug' => 2,

// Securty

'Cache.disable' => true,
'Security.salt' => 'SALT',
'Security.cipherSeed' => 'CIPHERSEED',

// Database

'MYSQL_DB_HOST' => 'localhost',
'MYSQL_USERNAME' => 'root',
'MYSQL_PASSWORD' => '',
'MYSQL_DB_NAME' => 'blwfun',
'MYSQL_PREFIX' => ''
),
function() {
if (!defined('FULL_BASE_URL')) {
define('FULL_BASE_URL', Configure::read('Settings.FULL_BASE_URL'));
}
}
);
?>


STAGING

 array('bellewaerdefun.be')
),
array(
// Site specific items

'Settings.FULL_BASE_URL' => 'http://bellewaerdefun.be',

// Email settings (maybe deprecated in 2.x)
'Email.username' => 'em...@example.com',
'Email.password' => 'password',
'Email.test' => 'em...@example.com',
'Email.from' => 'em...@example.com',

// App Specific functions

'debug' => 0,

// Securty
'Security.level' => 'medium',
'Security.salt' => 'SALT',
'Security.cipherSeed' => 'CIPHERSEED',

// Database

'MYSQL_DB_HOST' => 'localhost',
'MYSQL_USERNAME' => 'xxx',
'MYSQL_PASSWORD' => 'xxx',
'MYSQL_DB_NAME' => 'xxx',
'MYSQL_PREFIX' => ''
)
};
?>


After doing all of that, I thought my application would now automatically 
check the environment, but guess what: it doesn't! It keeps returning the 
default "development" environment. That's what happens in the Environment 
class (Plugin > Environments > Lib > Environment.php):

class Environment {

public $environments = array();

protected static $_instance;

protected $_configMap = array(
'security' => 'Security.level'
);

public static function () {
if (! self::$_instance) {
$Environment = 'Environment';
if (config('app_environment')) {
$Environment = 'App' . $Environment;
}

self::$_instance = new $Environment();
Configure::write('Environment.initialized', true);
}

return self::$_instance;
}

public static function configure($name, $params, $config = null, 
$callable = null) {
$_this = Environment::getInstance();
$_this->environments[$name] = compact('name', 'params', 'config', 
'callable');
}

public static function start($environment = null, $default = 
'development') {
$_this =& Environment::getInstance();
return $_this->setup($environment, $default);
}
...


Is there anyone who has the same problem as I have with this plugin? Or 
anyone who has a good solution to make my environments work?

Thanks a lot!

Additional info:
CakePHP version = 2.7.3
PHP version = 5.3.8

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Plugin appController beforeFilter() action doesn't work anymore

2015-10-21 Thread Sam Clauw
Since my update from CakePhp 2.3. to CakePhp 2.7., my beforeFilter() action 
in pluginAppController doesn't work anymore:

 array(
'loginAction' => array(
'plugin' => 'coaster_cms',
'controller' => 'users',
'action' => 'login'
),
'loginRedirect' => array(
'plugin' => 'coaster_cms',
'controller' => 'attractions',
'action' => 'index'
),
'authenticate' => array(
'Form' => array(
'passwordHasher' => 'Blowfish'
)
),
'authError' => 'No rights to visit this page.'
)
);

public function beforeFilter()
{
debug('test'); // No "test" output in any of my plugin actions
parent::beforeFilter()
}
}

?>

Does anybody knows what could possibly go wrong in my application that 
causes this?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


JSON string is showed instead of used

2015-05-31 Thread Sam Clauw
I recently added jQuery file upload 
(https://github.com/blueimp/jQuery-File-Upload) to my custom-made CMS 
system. Uploading images works fine, but loading the uploaded images 
doesn't. In fact: the JSON string appears on top of my file:

{files:[{name:foto1.jpg,size:221882,url:D:\\Websites\\Optiek 
 Cardoen\\05 - 
 Cake\\app\\webroot\\img\\outlets\\6\\foto1.jpg,thumbUrl:D:\\Websites\\Optiek
  
 Cardoen\\05 - 
 Cake\\app\\webroot\\img\\outlets\\6\\thumb\/foto1.jpg,deleteUrl:http:\/\/cake.optiekcardoen.be\/app\/webroot\/index.php?file=foto1.jpg,deleteType:DELETE},{name:foto2.jpg,size:184839,url:D:\\Websites\\Optiek
  
 Cardoen\\05 - 
 Cake\\app\\webroot\\img\\outlets\\6\\foto2.jpg,thumbUrl:D:\\Websites\\Optiek
  
 Cardoen\\05 - 
 Cake\\app\\webroot\\img\\outlets\\6\\thumb\/foto2.jpg,deleteUrl:http:\/\/cake.optiekcardoen.be\/app\/webroot\/index.php?file=foto2.jpg,deleteType:DELETE},{name:foto3
  
 (1).jpg,size:171300,url:D:\\Websites\\Optiek Cardoen\\05 - 
 Cake\\app\\webroot\\img\\outlets\\6\\foto3%20%281%29.jpg,thumbUrl:D:\\Websites\\Optiek
  
 Cardoen\\05 - 
 Cake\\app\\webroot\\img\\outlets\\6\\thumb\/foto3%20%281%29.jpg,deleteUrl:http:\/\/cake.optiekcardoen.be\/app\/webroot\/index.php?file=foto3%20%281%29.jpg,deleteType:DELETE},{name:foto3.jpg,size:171300,url:D:\\Websites\\Optiek
  
 Cardoen\\05 - 
 Cake\\app\\webroot\\img\\outlets\\6\\foto3.jpg,thumbUrl:D:\\Websites\\Optiek
  
 Cardoen\\05 - 
 Cake\\app\\webroot\\img\\outlets\\6\\thumb\/foto3.jpg,deleteUrl:http:\/\/cake.optiekcardoen.be\/app\/webroot\/index.php?file=foto3.jpg,deleteType:DELETE},{name:foto4.jpg,size:222763,url:D:\\Websites\\Optiek
  
 Cardoen\\05 - 
 Cake\\app\\webroot\\img\\outlets\\6\\foto4.jpg,thumbUrl:D:\\Websites\\Optiek
  
 Cardoen\\05 - 
 Cake\\app\\webroot\\img\\outlets\\6\\thumb\/foto4.jpg,deleteUrl:http:\/\/cake.optiekcardoen.be\/app\/webroot\/index.php?file=foto4.jpg,deleteType:DELETE}]}


How can I solve this so the JSON string doesn't appear like that anymore?

Here's the controller code in OutletPhotosController.php:

public function add()
{
App::import('Vendor', 'CoasterCms.UploadHandler', array('file' = 
'jQueryFileUpload' . DS . 'UploadHandler.php'));

$options = array(
'upload_dir' = WWW_ROOT . 'img' . DS . 'outlets' . DS . $this-
request-params['named']['outlet_id'] . DS,
'upload_url' = WWW_ROOT . 'img' . DS . 'outlets' . DS . $this-
request-params['named']['outlet_id'] . DS,
'accept_file_types' = '/\.(gif|jpe?g|png)$/i',
'image_versions' = array(
'thumb' = array(
'max_width' = 20,
'max_height' = 20,
'crop' = true
)
)
);


$upload_handler = new CustomUploadHandler($options);
}


And here's my very simple script in main.js:

script
$(function () {
'use strict';


// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({

});
});
/script

Thanks for helping ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Form width fieldset and different button types

2015-05-19 Thread Sam Clauw
FormHelper::inputs does create more than only input elements. I have forms 
where I've included textareas and selects in it.
So I hoped we could also put some submit and reset buttons in it ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Form width fieldset and different button types

2015-05-18 Thread Sam Clauw
Hi there!

I'm trying to use the jquery file uploader 
https://github.com/blueimp/jQuery-File-Upload/wiki in combination with 
CakePHP.

The HTML form uses 3 different button types:

   - submit (button type=submitStart upload/submit)
   - reset (button type=resetStart upload/submit)
   - button (button type=buttonStart upload/submit)

With CakePHP, I try to create those buttons via $this-Form-inputs, but I 
don't find out how I should sum up those different type of inputs.

I tried the following, but it ends up that those buttons are becoming input 
fields instead:

echo $this-Form-create('OutletPhoto', array(
'type' = 'file',
'novalidate' = true, // browser validatie
'inputDefaults' = array(
'label' = true,
'div' = 'form-group',
'class' = 'form-control'
),
'role' = 'form'
));

echo $this-Form-inputs(array(
'legend' = false,
'name' = array(
'type' = 'file',
'multiple',
'label' = false,
'id' = 'file_upload',
'name' = 'file_upload',
'class' = false,
'before' = 'Pick photos',
'after' = ''
),
'Start upload' = array(
'type' = 'submit',
'label' = false,
'class' = 'btn btn-primary start'
),
'Cancel upload' = array(
'type' = 'reset',
'label' = false,
'class' = 'btn btn-warning cancel'
),
'Delete' = array(
'type' = 'button',
'label' = false,
'class' = 'btn btn-danger delete'
)
));

echo $this-Form-end('Save');

Here's the HTML output of this code:

div class=form-groupdiv class=submit*input class=btn btn-primary 
start type=submit value=Start upload*/div/div
div class=form-group*input name=data[OutletPhoto][Cancel upload] 
class=btn btn-warning cancel type=reset id=OutletPhotoAnnuleerUpload*
/div
div class=form-groupbutton class=btn btn-danger delete 
type=submitDelete/button/div

Anyone who can tell me why my Start upload and Cancel upload don't show up 
as a button? Thanks in advance! ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


What are the advantages in using composite primary key since it has been supported in cakephp v3?

2015-04-29 Thread Sam
Cakephp 2.x did not support composite primary keys and it worked pretty 
fine. Cakephp 3.x added support for composite primary keys. I am not 
knowledgeable enough to know what are the advantages in using composite 
primary key. When should we use composite primary key?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


What are the improvements made on Cakephp ver3.x over the older versions?

2015-04-28 Thread Sam
I have used Cakephp ver2.x in the past and am pretty happy about it. Not 
sure if I should upgrade to ver3.x. May I know what are the improvements 
made in ver3.x compared to ver2.x? Any compelling improvements? So far, 
what are the grumbles, if any, with users who migrated from 2.x to 3.x?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: File upload validation

2015-03-01 Thread Sam Clauw
Charles, thank you for the great effort!
But is there no other option than move the validation into the controller 
instead of doing it in the model?

The code I wrote only contains one single if/else and is very clear to me. 
Okay, it's not working so I'm not getting anywhere for the moment huh ;)

Can you confirm that extension rule in CakePHP is validation the ['type'] 
variable in the FILES array? If yes, I realy don't understand why I keep 
getting validation errors on the validExtension rule :s

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: File upload validation

2015-02-28 Thread Sam Clauw
Okay Charles , that makes sense so I changed my code:

?php


class Outlet extends CoasterCmsAppModel
{
public $validate = array(
'name' = array(
'rule' = 'notEmpty', // verplicht
'message' = 'Nameis required.',
'allowEmpty' = true
),
'intro' = array(
'rule' = 'notEmpty', // verplicht
'message' = 'Intro is required.'
),
'photo' = array(
'validFileSize' = array( // zelf gekozen naam van de regel
'rule' = array('filesize', '', 0), // verplicht
'on' = 'create',
'message' = 'Photo is required.'
)
),
'photoTemp' = array(
'validExtension' = array( // zelf gekozen naam van de regel
'rule' = array('extension', array('jpg', 'jpeg', 'png', 
'gif')),
'on' = 'create',
'message' = 'Photo has to contain a valid extension (jpg, 
jpeg, png or gif).'
),
'validExtension' = array( // zelf gekozen naam van de regel
'rule' = array('extension', array('jpg', 'jpeg', 'png', 
'gif')),
'allowEmpty' = true,
'on' = 'update',
'message' = 'Photo has to contain a valid extension (jpg, 
jpeg, png or gif).'
)
)
);

public function beforeValidate()
{
$this-data['Outlet']['photoTemp'] = $this-data['Outlet']['photo'];
$this-data['Outlet']['photo'] = $this-data['Outlet']['photoTemp'][
'name'];
}

public function afterValidate()
{
$filename = $this-data['Outlet']['photo'];

if (!empty($filename)) {
move_uploaded_file($this-data['Outlet']['photoTemp']['tmp_name'
], WWW_ROOT . 'img' . DS . 'outlets' . DS . $filename);
} else {
unset($this-data['Outlet']['photo']);
}

unset($this-data['Outlet']['photoTemp']);
}
}


However, I still get the error message that I should upload a file with a 
correct extension. It's just like 'allowEmpty' = true isn't working at 
all.
I quess in my case it's checking the value in $this-data['Outlet'][
'photoTemp']['type'] so what could possibly be the problem?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


File upload validation

2015-02-28 Thread Sam Clauw
I have a problem with my file upload validation in CakePHP.

When I add a new record with an image upload field...

   - ... image should be required.
   - ... image file extension sould be jpg, png or gif.

When I edit an existing record with an image upload field...

   - ... image is not required.
   - ... when image is choosen: image file extension sould be jpg, png or 
   gif.

Here's my best model code attempt so far:

?php


class Outlet extends CoasterCmsAppModel
{
public $validate = array(
'name' = array(
'rule' = 'notEmpty', // verplicht
'message' = 'Name is required.',
'allowEmpty' = true
),
'intro' = array(
'rule' = 'notEmpty', // verplicht
'message' = 'Intro is required.'
),
'photo' = array(
'validFileSize' = array( // zelf gekozen naam van de regel
'rule' = array('filesize', '', 0), // verplicht
'on' = 'create',
'message' = 'Photo is required.'
),
'validExtension' = array( // zelf gekozen naam van de regel
'rule' = array('extension', array('jpg', 'jpeg', 'png', 
'gif')),
'on' = 'create',
'message' = 'Photo has to contain a valid extension (jpg, 
jpeg, png or gif).'
),
'validExtension' = array( // zelf gekozen naam van de regel
'rule' = array('extension', array('jpg', 'jpeg', 'png', 
'gif')),
'allowEmpty' = true,
'on' = 'update',
'message' = 'Photo has to contain a valid extension (jpg, 
jpeg, png or gif).'
)
)
);

public function afterValidate()
{
$filename = $this-data['Outlet']['photo']['name'];

if (!empty($filename)) {
move_uploaded_file($this-data['Outlet']['photo']['tmp_name'], 
WWW_ROOT . 'img' . DS . 'outlets' . DS . $filename);

$this-set('photo', $filename);
} else {
unset($this-data['Outlet']['photo']);
}
}
}


The add validation works fine for me. But strange as it is, when I edit a 
record, I keep getting the error message Photo has to contain a valid 
extension (jpg, jpeg, png or gif).
Somebody who can help me out of this? ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Problem with creating routes

2014-12-26 Thread Sam Clauw
I have a simple project that I'm trying to convert to a CakePHP 
project: http://optiekcardoen.be/home
The page navigation is very simple:

- Home (/)
- Shop (/shop)
- Products (/products)
- Frames (/products/frames)
- Sunglasses (/products/sunglasses)
- Lenses (/products/lenses)
- Hearing aids (/products/hearing-aids)
- Glass (/products/glass)
- Optometry (/products/optometry)
- Discounts (/discounts)
- Facts (/facts)
- Fotoshoots (/fotoshoots)
- Contact (/contact)

This is my current .htaccess file where I do the routing:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /


RewriteRule ^home$ index.php
RewriteRule ^producten/([^/\.]+)$ $1.php
RewriteRule ^([^/\.]+)$ $1.php

In CakePHP, routing should happen in app/Config/routes.php. Here's my 
attempt to fit the current routing in the CakePHP routing:

Router::connect('/', array('controller' = 'pages', 'action' = 'display', 
'home'));
Router::connect('/*', array('controller' = 'pages', 'action' = 'display'
));
Router::connect('/producten/:product-type',
 array('controller' = 'pages', 'action' = 'display'),
 array('pass' = array('product-type'))
);

Unfortunately, I get errors when I try to reach the product detail pages 
(e.g. /products/frames):

Missing View
 *Error: *The view for *PagesController::**display()* was not found.
 *Error: *Confirm you have created the file: D:\Websites\Optiek Cardoen\05 
 - Cake\app\View\Pages\producten\monturen.ctp
 *Notice: *If you want to customize this error message, create 
 app\View\Errors\missing_view.ctp


It says that the last rule in routes.php isn't correct, but how can I make 
it work to fill my needs?
Thanks in advance!

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Custom name for dropdown generated by formhelper

2014-12-12 Thread Sam Clauw
Is there no one who can help me out with this? ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Is there a way to put request variables in paginate class property?

2014-11-30 Thread Sam Clauw
I want to sort an array of data in my index action and one condition 
depends on the id given by the request object (attraction_id). Is there a 
way to set up the paginate component as a controller class method (see 
under)?

?php

class AttractionCommentsController extends CoasterCmsAppController
{
public $paginate = array(
'AttractionComment' = array(
'conditions' = array(
'Attraction.id' = *$this*
*-request-params['named']['attraction_id'**]*,
'AttractionComment.deleted' = null
),
'order' = array(
'AttractionComment.created' = 'DESC',
'AttractionComment.id' = 'ASC'
),
'limit' = 15
)
);

public function index()
{
$this-Paginator-settings = $this-paginate;

$comments = $this-Paginator-paginate('AttractionComment');

$this-set('comments', $comments);
}

?


The above code can't handle the request variable (*$this*
*-request-params['named']['attraction_id'**])* within the class method.
So... is there a solution for this or is it required to drop the class 
property and do something like this:

?php

class AttractionCommentsController extends CoasterCmsAppController
{
public function index()
{

$this-Paginator-settings = array(
'AttractionComment' = array(
'conditions' = array(
'Attraction.id' = $this-request-params['named'][
'attraction_id'],
'AttractionComment.deleted' = null
),
'order' = array(
'AttractionComment.created' = 'DESC',
'AttractionComment.id' = 'ASC'
),
'limit' = 15
)
); 
$comments = $this-Paginator-paginate('AttractionComment');

$this-set('comments', $comments);
}

?

Thx 4 helping!

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Custom name for dropdown generated by formhelper

2014-11-22 Thread Sam Clauw
I'm building a CMS system with a module called CmsPage' (list, add, edit, 
sort delete). Every cms page links via a select/select to another cms 
page and it tells which record the parent cms page is.
The select dropdown holds all the values from the table cms_pages. 

Here's my *add.php* with the form helper that shows a list with cms pages:

?php

echo $this-Form-create('CmsPage', array(
'type' = 'file',
'novalidate' = true,
'inputDefaults' = array(
'label' = true,
'div' = 'form-group',
'class' = 'form-control'
),
'role' = 'form'
));

echo $this-Form-inputs(array(
'legend' = false,
'name' = array(
'label' = 'Naam'
),
*'cmsPages'* = array(
'label' = 'Parent CMS page'
),
'plugin' = array(
'label' = 'Plugin'
),
'controller' = array(
'label' = 'Controller'
),
'action' = array(
'label' = 'Action'
)
));

echo $this-Form-end('Save');

?

Naming conventions *require* that the name of the select should 
becmsPages. But hey, I want to call it parentNode!
But when I do so, the dropdown changes in a simple textfield instead of the 
select dropdown.

Is to rename the red marked word above to parentNode? If yes... How? ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Question about using a CakePHP behavior

2014-11-19 Thread Sam Clauw
When you work with a self-made behavior and you create a public method in 
it, the first parameter should always be Model (predefined by CakePHP 
itself). Why is that?
I prefer to do a setter in the construct method of that behavior so I can 
call my model by $this-model...

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Is it a good idea to put AngularJS webpages onto Page folder?

2014-10-20 Thread Sam
I am currently using Cakephp mainly as REST server and AngularJS. The 
Angularjs webpages are put under webroot folder. Things have been working 
fine until I added user login authentication in Cakephp. For 
unauthenticated users who visit webpages in webroot, they are not directed 
to a login page. I thought of a solution but would like to seek advise from 
the more knowledgeable members here. Is it a good or even workable idea to 
put AngularJS webpages in the Page folder? What are the disadvantages in 
doing this? Or are there better alternatives?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Web service login function to check authenticate user in cakephp

2014-10-10 Thread Sam


I am writing a web service to authenticate whether a user login is valid or 
not. Below is a simple implementation of the web service placed inside 
UsersController.php

public function webservice_login() {
$this-autoRender = false;
if ($this-request-is('post')) 
{   
if ($this-Auth-login()) 
{
echo json_encode(array('ok_msg' = 'User authentication success'));
}
else
{
echo json_encode(array('fail_msg' = 'User authentication 
failure'));
}
} } 

It does not work. The error message I received is something like this;

\n\tError: \n\tPostsController could not be found.

\n
\n\tError: \n\tCreate the class PostsController below in file: 
app\\Controller\\PostsController.php

\n
\n?php\nclass PostsController extends AppController {\n\n}\n
\n
\n\tNotice: \n\tIf you want to customize this error message, create 
app\\View\\Errors\\missing_controller.ctp

What is wrong with the code? How should I rewrite the web service? I am 
using Cakephp 2.5. Strange thing is I do not have a controller called Post 
in the first place.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Web service login function to check authenticate user in cakephp

2014-10-10 Thread Sam
It is cakephp 2.5

On Saturday, October 11, 2014 9:53:21 AM UTC+8, Matthew Kaufman wrote:

 Is this Cake 2.6 or 3?

 On Fri, Oct 10, 2014 at 5:33 PM, Sam light...@gmail.com javascript: 
 wrote:

 I am writing a web service to authenticate whether a user login is valid 
 or not. Below is a simple implementation of the web service placed inside 
 UsersController.php

 public function webservice_login() {
 $this-autoRender = false;
 if ($this-request-is('post')) 
 {   
 if ($this-Auth-login()) 
 {
 echo json_encode(array('ok_msg' = 'User authentication 
 success'));
 }
 else
 {
 echo json_encode(array('fail_msg' = 'User authentication 
 failure'));
 }
 } } 

 It does not work. The error message I received is something like this;

 \n\tError: \n\tPostsController could not be found.

 \n
 \n\tError: \n\tCreate the class PostsController below in file: 
 app\\Controller\\PostsController.php

 \n
 \n?php\nclass PostsController extends AppController {\n\n}\n
 \n
 \n\tNotice: \n\tIf you want to customize this error message, create 
 app\\View\\Errors\\missing_controller.ctp

 What is wrong with the code? How should I rewrite the web service? I am 
 using Cakephp 2.5. Strange thing is I do not have a controller called Post 
 in the first place.

 -- 
 Like Us on FaceBook https://www.facebook.com/CakePHP
 Find us on Twitter http://twitter.com/CakePHP

 --- 
 You received this message because you are subscribed to the Google Groups 
 CakePHP group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to cake-php+u...@googlegroups.com javascript:.
 To post to this group, send email to cake...@googlegroups.com 
 javascript:.
 Visit this group at http://groups.google.com/group/cake-php.
 For more options, visit https://groups.google.com/d/optout.




-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Best practice to get menu array

2014-09-18 Thread Sam Clauw
Can I bump my topic again? :)
I realy hope I'll find an answer on this one, it's all about keeping the 
MVC as clear as possible ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Best practice to get menu array

2014-09-13 Thread Sam Clauw
I have 2 tables which hold pages information: pages and cms_pages. Now 
I want to build a menu on every website page with the records within. 
What's the best practice for this?

Should I make a behavior that loads in the pages and cms_pages model? 
If yes, where (and how) should I make the call to that behavior? In the 
AppModel class?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Make AppController variable available in pluginAppController

2014-09-12 Thread Sam Clauw
Okay, that's some basic stuff that I totally forgot! Thanks, it works fine 
now! ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Make AppController variable available in pluginAppController

2014-09-06 Thread Sam Clauw
In the AppController, I want to put the plugin, controller and action in 
variables just like this:

class AppController extends Controller
{
public $components = array(
'DebugKit.Toolbar',
'Session'
);

public function beforeFilter()
{
$plugin = $this-request-params['plugin'];
$controller = $this-request-params['controller'];
$action = $this-request-params['action'];
}
}

Now, I've made a plugin called CoasterCms. I thought every plugin got all 
the variables stored in AppController so I could get the plugin variable:

?php

class CoasterCmsAppController extends AppController
{
public $helpers = array(
'Html',
'Form',
'Session'
);

public $components = array(
'Session',
'Paginator'
);

public function beforeFilter()
{
debug($plugin);
}
}

However, it's not showing anything at all... What's the reason and how can 
I fix this?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


How to convert this php array into xml?

2014-08-21 Thread Sam


I am using cakephp v2.5. I would like to convert an array into xml. The 
array looks like this;

$Items = array(
(int) 0 = array(
'Item' = array(
'id' = '2'
)
),
(int) 1 = array(
'Item' = array(
'id' = '4'
)
))

To convert this array to xml, the following php code was run;

$xmlObject = Xml::fromArray(array('response' = $Items ));
echo $xmlObject-asXML();  

Unfortunately, the following error was encountered;

Warning (2): SimpleXMLElement::__construct(): Entity: line 3: parser error : 
Extra content at the end of the document [CORE\Cake\Utility\Xml.php, line 221]

I think I found the problem but still not have the solution. The output of 
array('response' 
= $Items) returns a maximum depth reached message. Anyone can advise?

How can this array be converted into xml in php or cakephp (using cake's 
built-in functions)?


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Best practice: using class on all pages

2014-08-14 Thread Sam Clauw
Okay, outputting an ulli structure with an element is indeed very 
usefull. It can appear in multiple areas on the template files. I 
understand that I should do something like:

echo $this-element('mainmanu', array(
'tree' = array(...),
'active' = array(...)
));

The tree array holds the records and should be calculated with a given 
depth.
The active array holds the parent nodes of the active node.

So far so good I guess? But what do you exactly mean with getting the data 
with a request action?
Sorry if this is a silly question :)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Best practice: using class on all pages

2014-08-10 Thread Sam Clauw
I want to write a class that use a left value and a depth value so it can 
print an ulli output for a menu. I want it to be able in my CMS plugin 
AND in my front-end pages. My question is: where should I put that class? 
Some options I've been thinking on:

   1. Everything in AppModel.php (disadvantage: file will be too long if 
   there are other functions here).
   2. Making a behavior and call it's functions in a helper.

Is one of the above options OK to use, or is there a better way to do so?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Authentication redirect problem when not logged in

2014-08-08 Thread Sam Clauw
Aha, a combination of you posts solved this problem ;)

However, I've got another one when trying to log in now. The password 
comparing doesn't work. The password values in my database are build up 
with the Blowfish hasher. When I'm submitting my login form, it compares 
the text value of the password with the Blowfish value of the password and 
returns always false.

*CoasterCmsAppController.php*

public $components = array(
'Session',
'Paginator',
'Auth' = array(
'loginAction' = array(
'plugin' = 'coaster_cms',
'controller' = 'users',
'action' = 'login'
),
'loginRedirect' = array(
'plugin' = 'coaster_cms',
'controller' = 'cms_pages',
'action' = 'index'
),
'logoutRedirect' = array(
'plugin' = 'CoasterCms',
'controller' = 'attractions',
'action' = 'index',
),
'authenticate' = array(
'Form' = array(
'passwordHasher' = 'Blowfish'
)
)
)
);

*UsersController.php (controller)*

public function login()
{
$this-layout = 'login';
if ($this-request-is('post')) {
if ($this-Auth-login()) {
return $this-redirect($this-Auth-redirect());
}
$this-Session-setFlash(__('Ongeldige login combinatie.'), 
'default', array(
'class' = 'alert alert-danger'
));
}
}

*login.ctp (login view)*

echo $this-Form-create('User', array(
'type' = 'file',
'novalidate' = true, // browser validatie
'inputDefaults' = array(
'label' = true,
'div' = 'form-group',
'class' = 'form-control'
),
'role' = 'form'
));


echo $this-Form-inputs(array(
'legend' = false,
'username' = array(
'label' = 'Gebruikersnaam'
),
'password' = array(
'label' = 'Wachtwoord'
)
));


echo $this-Form-end('Login');

*FYI: User.php (model)*

public function beforeSave($options = array())
{
if (isset($this-data[$this-alias]['password'])) {
$passwordHasher = new BlowfishPasswordHasher();
$this-data[$this-alias]['password'] = $passwordHasher-hash(
$this-data[$this-alias]['password']
);
}
return true;
} 

As I read in this StackOverflow post, the password input field should be 
converted automatically to the Blowfish hash and after that, the comparing 
should be done.
Am I forgetting something crucial?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Authentication redirect problem when not logged in

2014-08-08 Thread Sam Clauw
Okay, leave it guys! When I've posted my previous question, I suddenly 
realised that my database structure reserved 50 characters for the password 
field instead of 60. When changing this, it's all working great. Thanks 
anyway!!!

Op vrijdag 8 augustus 2014 12:11:38 UTC+2 schreef Sam Clauw:

 Aha, a combination of you posts solved this problem ;)

 However, I've got another one when trying to log in now. The password 
 comparing doesn't work. The password values in my database are build up 
 with the Blowfish hasher. When I'm submitting my login form, it compares 
 the text value of the password with the Blowfish value of the password and 
 returns always false.

 *CoasterCmsAppController.php*

 public $components = array(
 'Session',
 'Paginator',
 'Auth' = array(
 'loginAction' = array(
 'plugin' = 'coaster_cms',
 'controller' = 'users',
 'action' = 'login'
 ),
 'loginRedirect' = array(
 'plugin' = 'coaster_cms',
 'controller' = 'cms_pages',
 'action' = 'index'
 ),
 'logoutRedirect' = array(
 'plugin' = 'CoasterCms',
 'controller' = 'attractions',
 'action' = 'index',
 ),
 'authenticate' = array(
 'Form' = array(
 'passwordHasher' = 'Blowfish'
 )
 )
 )
 );

 *UsersController.php (controller)*

 public function login()
 {
 $this-layout = 'login';
 if ($this-request-is('post')) {
 if ($this-Auth-login()) {
 return $this-redirect($this-Auth-redirect());
 }
 $this-Session-setFlash(__('Ongeldige login combinatie.'), 
 'default', array(
 'class' = 'alert alert-danger'
 ));
 }
 }

 *login.ctp (login view)*

 echo $this-Form-create('User', array(
 'type' = 'file',
 'novalidate' = true, // browser validatie
 'inputDefaults' = array(
 'label' = true,
 'div' = 'form-group',
 'class' = 'form-control'
 ),
 'role' = 'form'
 ));


 echo $this-Form-inputs(array(
 'legend' = false,
 'username' = array(
 'label' = 'Gebruikersnaam'
 ),
 'password' = array(
 'label' = 'Wachtwoord'
 )
 ));


 echo $this-Form-end('Login');

 *FYI: User.php (model)*

 public function beforeSave($options = array())
 {
 if (isset($this-data[$this-alias]['password'])) {
 $passwordHasher = new BlowfishPasswordHasher();
 $this-data[$this-alias]['password'] = $passwordHasher-hash(
 $this-data[$this-alias]['password']
 );
 }
 return true;
 } 

 As I read in this StackOverflow post, the password input field should be 
 converted automatically to the Blowfish hash and after that, the comparing 
 should be done.
 Am I forgetting something crucial?


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Authentication redirect problem when not logged in

2014-08-06 Thread Sam Clauw
I reached the authentication part of my CakePHP based cms system, things 
are going very well (thanks to you guys) ;)
As in every application, I should ask for a username / password combination 
when somebody tries to get into my CMS. This CMS is build as a plugin and 
is called CoasterCms. Without login, you can reach it by the following 
url for example:

http://new.bellewaerdefun.be/coaster_cms/attractions/index


Now, when I change my CoasterCmsAppController.php and update my $components 
variable with the Auth array value:

class CoasterCmsAppController extends AppController
 {
 ...
 
 public $components = array(
 'Session',
 'Paginator'/*,
 'Auth' = array(
 'loginRedirect' = array(
 'plugin' = 'CoasterCms',
 'controller' = 'attractions',
 'action' = 'index'
 ),
 'logoutRedirect' = array(
 'plugin' = 'CoasterCms',
 'controller' = 'attractions',
 'action' = 'index',
 ),
 'authenticate' = array(
 'Form' = array(
 'passwordHasher' = 'Blowfish'
 )
 )
 )*/
 );
 ...
 }


... then I'm constantly redirected to the url:

http://new.bellewaerdefun.be/users/login


What's the reason of that and how can I change it so I can link it to the 
plugin? 

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Issue with COUNT() as query field

2014-07-29 Thread Sam Clauw
That does the trick for me, thx a lot!
BUT, I found out that when you use it in a behavior: it won't work at all. 
The array is shown as when you don't use the virtual fields:

array(
   (int) 0 = array(
 'CmsPage' = array(
   'id' = '2',
   'name' = 'Pagina's',
   'lft' = '2',
   'rgt' = '5',
   'plugin' = 'coaster_cms',
   'controller' = 'pages',
   'action' = 'index',
   'show' = 'Y',
   'deleted' = null
 ),
 (int) 0 = array(
   'CmsPage__depth' = '1'
 )
   ),
 ...


I tried to change the name of my virtual field etc, but it won't work. Any 
idea what could cause this?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Issue with COUNT() as query field

2014-07-29 Thread Sam Clauw
Sorry, my bad! I forgot to change the virtual field declaration to

$model-virtualFields['depth'] = 0;


Thanks anyway ;) 

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Behavior method won't work

2014-07-28 Thread Sam Clauw
Okay, I think I got it. I've made a single function as you suggested.

*Controller*

public function delete($id)
 {
 if ($this-request-is('get')) {
 throw new MethodNotAllowedException();
 }
 
 $this-Attraction-id = $id;
 
 if ($this-Attraction-softDelete($id)) {
 $this-Session-setFlash(__('The attraction with id %s was 
 successfully deleted.', h($id)), 'default', array(
 'class' = 'alert alert-success'
 ));
 }
 
 return $this-redirect(array(
 'action' = 'index'
 ));
 }


*AppModel*

 class AppModel extends Model {
 
 // Soft delete functionaliteit
 
 public function beforeDelete()
 {
 if ($this-hasField('deleted')) {
 $this-saveField('deleted', date('Y-m-d H:i:s'));
 }
 
 return false;
 }
 
 public function softDelete($id)
 {
 $this-delete($id);
 
 $record = $this-find('count', array(
 'conditions' = array(
 {$this-alias}.id = $id,
 {$this-alias}.deleted != = null
 )
 ));
 if ($record  0) {
 return true;
 }
 }
 }


And that works fine for me now! Stephen, thank you for you time and thank 
you very much to support me on this one!
I've pasted my code here so others can use this functionality too! ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Behavior method won't work

2014-07-27 Thread Sam Clauw
Okay, that was very helpful, thanks! I've moved the functionality to 
AppModel now and it works.
One other additional problem: the application expects a view file now:

*Error: *The view for *AttractionsController::**delete()* was not found.


How can you prevent it from loading a view file? :)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Behavior method won't work

2014-07-27 Thread Sam Clauw
Hmmm, that doesn't work out for me. It seems that it tries to execute a 
query:

*Error: *SQLSTATE[42000]: Syntax error or access violation: 1064 You have 
 an error in your SQL syntax; check the manual that corresponds to your 
 MySQL server version for the right syntax to use near 'referer' at line 1
 *SQL Query: *referer


This is my current AppModel:

class AppModel extends Model {
 
 // soft delete functionaliteit
 
 public function beforeDelete()
 {
 if ($this-hasField('deleted')) {
 if ($this-saveField('deleted', date('Y-m-d H:i:s'))) {
 return $this-redirect($this-referer());
 }
 }
 }
 }


I guess $this-redirect() should always been done in a controller? Or is 
there a way to catch it in the model? 

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Behavior method won't work

2014-07-27 Thread Sam Clauw
Well, the weird thing is that's how I originally wrote it, and that won't 
work. An illustration of how it all looks right now:

*Controller (AttractionsController.php)*

public function delete($id)
{
if ($this-request-is('get')) {
throw new MethodNotAllowedException();
}

$this-Attraction-id = $id;

if ($this-Attraction-delete($id)) {
$this-Session-setFlash(__('De attractie met id %s werd succesvol 
verwijderd.', h($id)), 'default', array(
'class' = 'alert alert-success'
));

return $this-redirect(array(
'action' = 'index'
));
}
}

*AppModel*

class AppModel extends Model {

// soft delete functionality

public function beforeDelete()
{
if ($this-hasField('deleted')) {
if ($this-saveField('deleted', date('Y-m-d H:i:s'))) {
return false;
}
}
}
}

I'm still getting the error:

Missing View
 *Error: *The view for *AttractionsController::**delete()* was not found.
 *Error: *Confirm you have created the file: 
 D:\Websites\BellewaerdeFun\app\Plugin\CoasterCms\View\Attractions\delete.ctp

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Behavior method won't work

2014-07-27 Thread Sam Clauw
Allright, I should know that, you're totally right! It works for my now, 
except my flash error of course. I could put it outside the if 
($this-Attraction-delete($id)) {} check, but then the flash would always 
been shown, even if there was no delete...

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Behavior method won't work

2014-07-26 Thread Sam Clauw
I'll try to write my very first behavior that does a soft delete instead of 
a hard delete. I've expanded my model with

public $actsAs = array('SoftDelete');


and I've created the behavior SoftDeleteBehavior.php in 
App/Model/Behavior:

 

 ?php
 App::uses('ModelBehavior', 'Model');
 class SoftDeleteBehavior extends ModelBehavior
 {
 function setup(Model $Model, $settings = array())
 {
 
 }
 
 function delete(Model $Model, $id = null)
 {
 $Model-id = $id;
 
 if ($Model-saveField('deleted', date('Y-m-d H:i:s'))) {
 return true;
 }
 return false;
 }
 }


However, when I try to delete something, the delete() method from my 
behavior doesn't overwrite the normal one. What could cause this issue?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Cakephp Webservice

2014-07-26 Thread Engleang Sam
Dear All,

I have problem with saving image that upload from IOS objective C. My 
friend does it with AFnetworking , framework of objective-c while I could 
not find any files to save in Cakephp. Any solution or comment would be 
appreciated!

Best regard,

Engleang

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


How to calculate in array from $this-model-updateAll()?

2014-07-17 Thread Sam Clauw
I try to do an update all in my add action with the following method:

$this-CmsPage-updateAll(
 array(
 'CmsPage.rgt' = *('CmsPage.rgt' + 2)*
 ),
 array(
 'CmsPage.rgt ' = $right
 )
 );


Unfortunately, i'ts not working. It keeps sending the value 2 to the rgt 
field in my database table.
So my question is: what's should be changed in my array (2 + 'CmsPage.rgt) 
to do such calculations? :)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Issue with COUNT() as query field

2014-07-08 Thread Sam Clauw
What I'm trying to do is making a self join to get a menu tree structure 
out of the database. It almost works with this code:

$this-set('cmsPages', $this-CmsPage-find('all', array(
'fields' = array(
'CmsPage.name',
'CmsPage.lft',
'CmsPage.rgt',
'(COUNT(CmsPage.name) - 1) as depth'
),
'joins' = array(
array('table' = 'cms_pages',
'alias' = 'Parent',
'type' = 'LEFT',
'conditions' = array(
'CmsPage.lft BETWEEN Parent.lft AND Parent.rgt',
'CmsPage.deleted' = null
)
)
),
'group' = array(
'CmsPage.plugin',
'CmsPage.controller',
'CmsPage.action'
),
'order' = array(
'CmsPage.lft ASC'
)
)));[/php]

The only thing that doesn't fit my needs is how the array is build when 
using count() as a field:

array(
(int) 0 = array(
'CmsPage' = array(
'name' = 'Add item',
'lft' = '1',
'rgt' = '22',
'plugin' = 'coaster_cms',
'controller' = 'cms_pages',
'action' = 'index'
),
*(int) 0 = array(*
* 'depth' = '2',*
* )*
),
...
)

That should be the output that I realy need:

array(
(int) 0 = array(
'CmsPage' = array(
'name' = 'Add item',
'lft' = '1',
'rgt' = '22',
'plugin' = 'coaster_cms',
'controller' = 'cms_pages',
'action' = 'index'
*'depth' = '2'*
)
)
)
Can anyone help me with this small issue? ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Cookbook: database query in controller???

2014-07-07 Thread Sam Clauw
Okay, that's very clear to me. Thanks a lot guys!!!

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Cookbook: database query in controller???

2014-07-06 Thread Sam Clauw
I've a question about the MVC in CakePHP. Normally, the model should take 
responsability for all the database queries.

However, in the cookbook documentation, it seems this isn't respected. See 
the following link: 
http://book.cakephp.org/2.0/en/getting-started.html#create-a-posts-controller

As you can see, the index action of PostsController contains $this-Post-
find('all'). Shouldn't this and this code for example:

$this-set('areas', $this-Attraction-Area-find('list', array(
 'conditions' = array(
 'Area.deleted' = null
 ),
 'order' = array(
 'Area.sequence ASC',
 'Area.name ASC'
 )
 )));


not be in the Model part instead of in the controller part???

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Uploading a picture file from mobile app to Cakephp

2014-07-02 Thread Sam
I would like have an Android mobile app snap pictures and then upload the 
pictures to a Cakephp web application. 

Is creating web services on Cakephp for the mobile app to call to upload 
the image file the right approach? Is it possible to have the mobile app do 
a HTTP Post to upload the file? If not, what are the good ways of uploading 
a picture file from mobile app to Cakephp? Are there any good sample code 
on the web?

Thank you.


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: How to self join?

2014-06-16 Thread Sam Clauw
Well, it seems there are 2 problems with you suggested query. Here's the 
SQL error I've got:

*Error: *SQLSTATE[42S22]: Column not found: 1054 Unknown column 
 'CmsPage.null' in 'on clause'
 *SQL Query:  *SELECT `CmsPage`.`id`, `CmsPage`.`parent_id`, 
 `CmsPage`.`name`, `CmsPage`.`lft`, `CmsPage`.`rgt`, `CmsPage`.`plugin`, 
 `CmsPage`.`controller`, `CmsPage`.`action`, `CmsPage`.`show`, 
 `CmsPage`.`sequence`, `CmsPage`.`created`, `CmsPage`.`modified`, 
 `CmsPage`.`deleted`, `Parent`.`id`, `Parent`.`parent_id`, `Parent`.`name`, 
 `Parent`.`lft`, `Parent`.`rgt`, `Parent`.`plugin`, `Parent`.`controller`, 
 `Parent`.`action`, `Parent`.`show`, `Parent`.`sequence`, 
 `Parent`.`created`, `Parent`.`modified`, `Parent`.`deleted` FROM 
 `blwfun`.`cms_pages` AS `CmsPage` LEFT JOIN `blwfun`.`cms_pages` AS 
 `Parent` ON (`CmsPage`.`null` = `Parent`.`id` AND `CmsPage`.`lft` BETWEEN 
 `Parent`.`lft` and `Parent`.`rgt`) WHERE `CmsPage`.`deleted` IS NULL LIMIT 
 20


So, I changed my model to:

class CmsPage extends CoasterCmsAppModel
{
public $belongsTo = array(
'Parent' = array(
'className' = 'CoasterCms.CmsPage',
/*'foreignKey' = 'null',*/
'conditions' = array(
'CmsPage.lft BETWEEN Parent.lft and Parent.rgt'
)
)
);

public $virtualFields = array(
'depth' = '(COUNT(Parent.name) - 1)'
);
}

The only problem is now that I only got one row in return, with a wrong 
depth value...
Somebody who knows what I'm still doing wrong? Or somebody who know how I 
can output all SQL statements as a string? The only code I can find is:

$log = $this-Model-getDataSource()-getLog(false, false); debug($log);


But I cannot do anything with that output:

array(
'log' = array(),
'count' = (int) 0,
'time' = null
)


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


How to self join?

2014-06-15 Thread Sam Clauw
Hi there,

what I try to do is to make a self join in my controller. The only problem 
is I can't find any documentation about it in the cookbook 2.x about it.

My uncaked query looks like this:

SELECT
node.name, (COUNT(parent.name) - 1) AS depth
FROM
cms_pages AS node,
cms_pages AS parent
WHERE
node.lft BETWEEN parent.lft AND parent.rgt
GROUP BY
node.name
ORDER BY
node.lft

This is my current code that should be extended:

$mainMenu = $this-CmsPage-find('all', array(
'conditions' = array(
'CmsPage.lft BETWEEN ? AND ?' = array(
$mainMenuRoot['CmsPage']['lft'],
$mainMenuRoot['CmsPage']['rgt']
),
'CmsPage.deleted' = null
),
'order' = array(
'CmsPage.lft ASC'
)
));

Is there someone who has a solution for this? Can I solve it in my 
controller, of should I extend my model? :)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


How to get URL parameters in cakephp with URL that ends with xml?

2014-06-04 Thread Sam


I would like to pass URL parameters in cakephp with URL that ends with xml 
like below;

http://localhost/cp251/controller/api_get_info?page=1.xml

The controller function looks like this;

public function api_get_info(){
if($this-RequestHandler-responseType() == 'xml')
{
//Problem is that the code never executes inside this if statement
//Controller action

}}

The problem is that the code never executes inside the if statement 
if($this-RequestHandler-responseType() 
== 'xml'). However, if the URL becomes 
http://localhost/cp251/controller/api_get_info.xml, then the code will 
execute inside the if statement. Unfortunately, this is not what I want 
because the URL parameters cannot be sent.

How can I pass URL parameters in cakephp with URL that ends with xml? I am 
using cakephp 2.5.1

Thank you.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


How to redirect all webpages under webroot to login page?

2014-05-15 Thread Sam


I am using cakephp 2.4.5. I would like to redirect all users who have not 
logged in to a login page. I basically followed the instructions here 
http://miftyisbored.com/a-complete-login-and-authentication-application-tutorial-for-cakephp-2-3/

In summary, the important part is the following code to AppController.php

public $components = array('Session',
'Auth' = array(
'loginRedirect' = array('controller' = 
'users', 'action' = 'index'),
'logoutRedirect' = array('controller' = 
'users', 'action' = 'login'),
'authError' = 'You must be logged in to view 
this page.',
'loginError' = 'Invalid Username or Password 
entered, please try again.'
));

Any websites with this URL format 
http://localhost/cakephp245/controllers/XXX will be re-directed to the 
login page. However, websites that are located inside webroot with URL that 
looks like thishttp://localhost/TTSH-CP245/app/webroot/XXX will not be 
re-directed to the login page.

How can I get websites located inside app/webroot folder to be re-directed 
to the login page?

Thank you very much.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Redirect all webpages under webroot to login page

2014-05-15 Thread Sam


I am using cakephp 2.4.5. I would like to redirect all users who have not 
logged in to a login page. I basically followed the instructions here 
http://miftyisbored.com/a-complete-login-and-authentication-application-tutorial-for-cakephp-2-3/

In summary, the important part is the following code to AppController.php

public $components = array('Session',
'Auth' = array(
'loginRedirect' = array('controller' = 
'users', 'action' = 'index'),
'logoutRedirect' = array('controller' = 
'users', 'action' = 'login'),
'authError' = 'You must be logged in to view 
this page.',
'loginError' = 'Invalid Username or Password 
entered, please try again.'
));

Any websites with this URL format http://localhost/cakephp245/controllers/XXX 
will be re-directed to the login page. However, websites that are located 
inside webroot with URL that looks like 
thishttp://localhost/cakephp245/app/webroot/XXX will not be re-directed to the 
login page.

How can I force websites located inside app/webroot folder to be re-directed to 
the login page?

Thank you very much.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Multi-level menu with Modified Preorder Tree Traversal

2014-04-06 Thread Sam Clauw
Hi Marco, thanks 4 your answer too! I realy do appreciate those great 
scripts you're sending to me. But right now, I still got the problem that I 
can't write the essence of a multi-level menu (without recursion) on my own 
;)
Perhaps, you can tell me if / how I can cross my tree-based database table 
and output it in a realy simple ulli list? No active class of whatever, 
but the real essence would help me a lot! :)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: Multi-level menu with Modified Preorder Tree Traversal

2014-04-01 Thread Sam Clauw
Hi euromark,

I did noticed your article, but I don't want to put the whole Tools plugin 
into my system...
In fact, the most important thing is that I can code such a tree by myself 
(and with soms exterial forum help of course) ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Multi-level menu with Modified Preorder Tree Traversal

2014-03-31 Thread Sam Clauw
Hi all,

In this http://www.sitepoint.com/hierarchical-data-database-2/ well known 
example, the indention of the levels is done by some nbsp;'s instead of 
ulli's.
I wonder if there's a way to use MPPT (Modified Preorder Tree Traversal) 
logic to dynamically build those multi-level menu without using any 
recursion?  I can't figure out where I have to close those ul's and 
li's... :s

Thx!

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


What are the pros and cons of using find() versus SQL queries?

2014-03-27 Thread Sam
What are the pros and cons of using find() versus SQL queries? If one is 
already familiar with SQL, is it advisable to use them throughout in 
cakephp?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Moving data from 1 pair of table to another similar pair

2014-03-25 Thread Sam


I have 2 similar pairs of tables (Table1 and Table2, TableA and TableB).

Table1 has many Table2. Table2 belongs to Table1. In other words, there is 
a one-to-many relationship between Table1 and Table2. TableA and TableB has 
the same one-to-many relationship as Table1 and Table2.

I would like to move a row in Table1 plus all the associated rows in Table2 
to the matching table pair TableA and TableB.

What is the best way to transfer the table row and the associated rows? Do 
I save each row to the new table one by one using save() or is there a way 
to save all the rows at one go using saveall()?

Is it a problem to use saveall() to do the data transfer if the table 
fields are similar but not exactly the same. Between the table pair, some 
rows are the same and some rows are different.

I am using Cakephp 2.4.5. Thank you for your help.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


How to remove response element from json web service when using _serialize in Cakephp?

2014-03-18 Thread Sam


Cakephp _serialize() automatically appends a response element when it is 
used to generate a json web service. This response element causes problem 
for the front-end to parse. How can this response element be removed from 
Cakephp? I am using Cakephp 2.4.5

http://book.cakephp.org/2.0/en/views/json-and-xml-views.html

I asked this question on Stack Overflow but could not get any answers. I 
wonder if the experts here can give me some advice. Thanks a lot in advance.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


How to return json message inside controller?

2014-03-13 Thread Sam


I have a controller which takes in an id and checks whether this id exists 
inside the Model. If it does not exist, I would like the controller to 
return a validation error message id not found in json when it returns 
the HTTP response. This controller takes in a normal HTTP POST which is not 
in json.

How can this be done in Cakephp 2.4.5?

My controller code looks something like this;

public function controller_function($id=null){
if ($this-request-is('post')) 
{
   $field=$this-request-data['Model']['field'];
   $Model_id = $this-Model-findFieldID($field);
   if (empty($Model_id) ) //record not found. Return validation error
   {
   //Send validation error back in JSON. How??
   }
}}

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: How to return json message inside controller?

2014-03-13 Thread Sam


On Thursday, March 13, 2014 7:21:26 PM UTC+8, wchopite wrote:

 Use the php function json_encode( ). 

 http://php.net/manual/en/function.json-encode.php

 You can generate an associative array with the message you want, and use:

 return json_encode($your_array);

Thanks. This worked. I can see the json message in the HTTP response. But I 
still have a problem. When I look at the HTTP response, it is full of other 
HTML code besides the json message. How can I remove the other HTML code 
and leave behind only a clean json message? 

Thank you.
 

 Wladimir Chópite
 +584249700264
 ve.linkedin.com/in/wchopite
 Mejor pirata de la armada. Hack the planet! 
 El 13/03/2014 06:45, Sam light...@gmail.com javascript: escribió:

 I have a controller which takes in an id and checks whether this id 
 exists inside the Model. If it does not exist, I would like the controller 
 to return a validation error message id not found in json when it returns 
 the HTTP response. This controller takes in a normal HTTP POST which is not 
 in json.

 How can this be done in Cakephp 2.4.5?

 My controller code looks something like this;

 public function controller_function($id=null){
 if ($this-request-is('post')) 
 {
$field=$this-request-data['Model']['field'];
$Model_id = $this-Model-findFieldID($field);
if (empty($Model_id) ) //record not found. Return validation error
{
//Send validation error back in JSON. How??
}
 }}

  -- 
 Like Us on FaceBook https://www.facebook.com/CakePHP
 Find us on Twitter http://twitter.com/CakePHP

 --- 
 You received this message because you are subscribed to the Google Groups 
 CakePHP group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to cake-php+u...@googlegroups.com javascript:.
 To post to this group, send email to cake...@googlegroups.comjavascript:
 .
 Visit this group at http://groups.google.com/group/cake-php.
 For more options, visit https://groups.google.com/d/optout.



-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: How to return json message inside controller?

2014-03-13 Thread Sam


On Thursday, March 13, 2014 7:29:42 PM UTC+8, wchopite wrote:

 Use at the beginning of your controller function:

 $this-autoRender=false;


Thanks. This worked. I still get some error message like this; 
Notice (8): Undefined offset: 0 [APP\\Model\\Model1.php, line 23] 
Are those cakephp debug messages? Can I remove them by setting the debug 
level down? 
 

 Wladimir Chópite
 +584249700264
 ve.linkedin.com/in/wchopite
 Mejor pirata de la armada. Hack the planet! 
 El 13/03/2014 06:57, Sam light...@gmail.com javascript: escribió:



 On Thursday, March 13, 2014 7:21:26 PM UTC+8, wchopite wrote:

 Use the php function json_encode( ). 

 http://php.net/manual/en/function.json-encode.php

 You can generate an associative array with the message you want, and use:

 return json_encode($your_array);

 Thanks. This worked. I can see the json message in the HTTP response. But 
 I still have a problem. When I look at the HTTP response, it is full of 
 other HTML code besides the json message. How can I remove the other HTML 
 code and leave behind only a clean json message? 

 Thank you.
  

 Wladimir Chópite
 +584249700264
 ve.linkedin.com/in/wchopite
 Mejor pirata de la armada. Hack the planet! 
 El 13/03/2014 06:45, Sam light...@gmail.com escribió:

 I have a controller which takes in an id and checks whether this id 
 exists inside the Model. If it does not exist, I would like the controller 
 to return a validation error message id not found in json when it 
 returns 
 the HTTP response. This controller takes in a normal HTTP POST which is 
 not 
 in json.

 How can this be done in Cakephp 2.4.5?

 My controller code looks something like this;

 public function controller_function($id=null){
 if ($this-request-is('post')) 
 {
$field=$this-request-data['Model']['field'];
$Model_id = $this-Model-findFieldID($field);
if (empty($Model_id) ) //record not found. Return validation error
{
//Send validation error back in JSON. How??
}
 }}

  -- 
 Like Us on FaceBook https://www.facebook.com/CakePHP
 Find us on Twitter http://twitter.com/CakePHP

 --- 
 You received this message because you are subscribed to the Google 
 Groups CakePHP group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to cake-php+u...@googlegroups.com.
 To post to this group, send email to cake...@googlegroups.com.
 Visit this group at http://groups.google.com/group/cake-php.
 For more options, visit https://groups.google.com/d/optout.

  -- 
 Like Us on FaceBook https://www.facebook.com/CakePHP
 Find us on Twitter http://twitter.com/CakePHP

 --- 
 You received this message because you are subscribed to the Google Groups 
 CakePHP group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to cake-php+u...@googlegroups.com javascript:.
 To post to this group, send email to cake...@googlegroups.comjavascript:
 .
 Visit this group at http://groups.google.com/group/cake-php.
 For more options, visit https://groups.google.com/d/optout.



-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


How to send HTTP POST in non-json and get HTTP response in json?

2014-03-12 Thread Sam


I want to add records to a table using a normal HTTP POST. The payload will 
look something like data[Model][fieldName]. The HTTP Post is done in json 
format.

However, I would like the HTTP Response which contains the data validation 
message to be in json format. Currently, Cakephp will return the HTTP 
response in HTML. How can I change it to return the HTTP response in json?

Thank you.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


What HTTP POST format to use for saving model and associated model data in a single controller function?

2014-03-12 Thread Sam


I am using Cakephp 2.4.5. I have 2 tables with a one-to-many relationship. 
Table B belongs to Table A. Table A has many Table B.

I want a controller in Table A that can save records in Table A and Table 
B. The controller code should be simple and looks like this;

public function add_tableA($id=null){
if ($this-request-is('post')) 
{
$this-layout = null ;
$this-TableA-create();
$this-TableA-saveAll($this-request-data, array('deep' = true));
}}

My problem comes when trying to send the right HTTP POST format to the 
controller.

I tried to HTTP POST the data format below but it fails.

data[TableA][field1] = field1_value
data[TableA][field2] = field2_value
data[TableB][field1] = field1_value
data[TableB][field2] = field2_value

Then, I try to HTTP POST the data format below, at least TableA fields are 
populated.

data[TableA][field1] = field1_value
data[TableA][field2] = field2_value

How should the HTTP POST data format look like if I want to create rows for 
both tables?


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: What HTTP POST format to use for saving model and associated model data in a single controller function?

2014-03-12 Thread Sam
Thank you. Your answer is correct.

On Wednesday, March 12, 2014 6:03:05 PM UTC+8, José Lorenzo wrote:

 If A hasmany B then the format should be: 

 data[TableA][field1] = field1_value
 data[TableA][field2] = field2_value
 data[TableB][0][field1] = field1_value
 data[TableB][0][field2] = field2_value

 On Wednesday, March 12, 2014 10:38:00 AM UTC+1, Sam wrote:

 I am using Cakephp 2.4.5. I have 2 tables with a one-to-many 
 relationship. Table B belongs to Table A. Table A has many Table B.

 I want a controller in Table A that can save records in Table A and Table 
 B. The controller code should be simple and looks like this;

 public function add_tableA($id=null){
 if ($this-request-is('post')) 
 {
 $this-layout = null ;
 $this-TableA-create();
 $this-TableA-saveAll($this-request-data, array('deep' = true));
 }}

 My problem comes when trying to send the right HTTP POST format to the 
 controller.

 I tried to HTTP POST the data format below but it fails.

 data[TableA][field1] = field1_value
 data[TableA][field2] = field2_value
 data[TableB][field1] = field1_value
 data[TableB][field2] = field2_value

 Then, I try to HTTP POST the data format below, at least TableA fields 
 are populated.

 data[TableA][field1] = field1_value
 data[TableA][field2] = field2_value

 How should the HTTP POST data format look like if I want to create rows 
 for both tables?




-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


How to update data in several models in a single Web Service?

2014-03-08 Thread Sam
There are 3 tables in my database. Table1 has a one-to-many relationship to 
Table2. Table2 has a one-to-many relationship to Table3. I would like to 
write a web service API that allows the user to add rows to all 3 tables at 
the same time. The problem with CakePHP is that it only allows a controller 
to access its own corresponding model's data. How can a controller access 
other models? What is the best practices for CakePHP for a single 
controller to access other models? For my case in particular, which table 
should I use? Will Table1 be a good start since it is the parent to the 
other tables?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


What are the advantages and disadvantages(if any) to use cakephp3.0?

2014-02-28 Thread Sam
What are the advantages and disadvantages(if any) to use cakephp3.0 instead 
of cakephp2.x?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Dynamic menu content in layout

2014-02-26 Thread Sam Clauw
Okay, let's suppose I want to put my menu in an element called 
top_menu.ctp. I want to get my data out of the database, so probably, I 
shouldn't connect with my database in that .ctp file. I wonder if that's 
the right way to do so? MVC normally split us the model logic and the view 
logic, but now you'll all get it in one file? Or am I missing something? ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


How to copy a record and its associated records to another 2 tables?

2014-02-25 Thread Sam
I have 2 tables with a one-to-many relationship. I have another 2 similar 
tables with the same relationship in the same database. I would like to 
copy a record and its associated records from one pair to another. Can 
someone advise?

Thank you very much.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Any problems if foreign key is defined in the table creation SQL script?

2014-02-23 Thread Sam
In cakephp, the table relationship is defined in the Models and no foreign 
key needs to be defined in the table creation SQL script. However, I have a 
SQL script created using MySQL workbench that defines the foreign key. Will 
this be a problem in cakephp?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Dynamic menu content in layout

2014-02-22 Thread Sam Clauw


What I'm trying to do is to put two dynamic navigation menus in my CakePHP 
layout (default.ctp). The main menu should have multiple levels (with a 
dropdown functionality). The secondary menu is the one that shows the 
dropdown content of the main menu in a left sidebar.

I've read the CakePHP documentation but I'm confused how to fit those menus 
in the layout. I know that you have 4 different parts in a view layer (as 
documented in http://book.cakephp.org/2.0/en/views.html):

   - views
   - elements
   - layouts
   - helpers

But with the knowledge I have right now, I think none of this parts can be 
used to fill my needs. A navigation menu is a part that you only load ONES 
in a layout, so it isn't an element or a helper. So what's the best 
practice...

   - ... where to create the menu tree?
   - ... where / how to echo it in the layout file?

Can anybody clearify my issue? Thanks in advance! ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


How to write custom SQL queries instead of using find()?

2014-02-20 Thread Sam
While find() is good enough for most, I would like to write custom SQL 
queries instead of using find(). How can that be done in cakephp?

Thank you.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Can HTTP POST response size be minimized?

2014-02-12 Thread Sam


I have an application which sends plenty of HTTP POST to add records to a 
cakephp 2.3 application which was cake baked. I noticed that the HTTP 
response from cakephp is quite big. Can HTTP POST response size be 
minimized? I don't really care about the response. Please note that I am 
not sending HTTP POST through a form but through an external app written in 
python.


Thank you.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


How does HTTP Post URL for adding multiple records look like?

2014-02-10 Thread Sam
Dear CakePHP gurus,

I would like to add multiple records to a single model in a single HTTP 
post. For single record, the HTTP post will look something like 
http://127.0.0.1/app/model/api_add/data[Model][Field1];. How will the HTTP 
Post URL look like for adding multiple records? I will tried different sort 
of combination but failed.

Below is the add() in the Controller.
public function add() 
{ 
if ($this-request-is('post')) 
{
$this-Model-create();
$this-Model-saveAll($this-request-data);
}
}

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Date modified isn't null when adding a record

2014-02-09 Thread Sam Clauw


Normally, when you add a record with a form to a database table, CakePHP 
will automatically fill in the created field in de database with the 
current date  time. It works for my table called attractions (model 
Attraction).

But now, strange things are happening. When I add a record for:

   - model AttractionProperty, table attraction_properties
   - model AttractionTypes, table attraction_types
   - model AttractionPropertyLink, table attraction_properties_links
   - ...

... both the fields created and modified are filled in. I checked if 
the id of my model is set in the add action ($this-request-id), but it 
says false.

Here's my controller code:

 public function add()
 {
 if ($this-request-is('post')) {
 $this-AttractionProperty-create();
 if ($this-AttractionProperty-save($this-request-data)) { // 
 data array opslaan
 $this-Session-setFlash(__('De eigenschap werd succesvol 
 toegevoegd.'), 'default', array(
 'class' = 'alert alert-success'
 ));
 return $this-redirect(array(
 'action' = 'index'
 ));
 }
 $this-Session-setFlash(__('Er is een fout tijdens het toevoegen 
 van de eigenschap opgetreden.'), 'default', array(
 'class' = 'alert alert-danger'
 ));
 }
 }
 public function edit($id = null)
 {
 if (!$id) {
 throw new NotFoundException(__('Ongeldige eigenschap.'));
 }
 $property = $this-AttractionProperty-findById($id);
 if (!$property) {
 throw new NotFoundException(__('Ongeldige eigenschap.'));
 }
 if ($this-request-is(array('post', 'put'))) {
 $this-AttractionProperty-id = $id;
 if ($this-AttractionProperty-save($this-request-data)) { // 
 data array opslaan
 $this-Session-setFlash(__('De eigenschap werd succesvol 
 bewerkt.'), 'default', array(
 'class' = 'alert alert-success'
 ));
 return $this-redirect(array(
 'action' = 'index'
 ));
 }
 $this-Session-setFlash(__('Er is een fout tijdens het bewerken 
 van de eigenschap opgetreden.'), 'default', array(
 'class' = 'alert alert-danger'
 ));
 }
 if (!$this-request-data) {
 $this-request-data = $property;
 }
 }


I did read 
http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-save-array-data-null-boolean-validate-true-array-fieldlist-array
 to 
retrieve more info, but it seems that I've done everything to the rules. I 
also know that you can do 

 if ($this-AttractionProperty-save($this-request-data(array('modified' 
 = false {
 
 }


when you save in the add action, but I realy want to know what's the 
underlying problem ;)

Is this a common problem or what could be the reason of this behavior?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Date modified isn't null when adding a record

2014-02-09 Thread Sam Clauw
Okay, that's totally clear to me now. At first sight, I thought there 
shouldn't be a date modified when adding a record. But that's the second 
system that do save a date create and a date modified when adding a 
record. Thanks 4 the clarification!

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Paginator isn't sorting

2014-02-09 Thread Sam Clauw
I would like to sort my index list on sequence ASC, but it won't work. If I 
see the query setup in the CakePHP docs 
(http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html#query-setup),
 
my paginator settings should look like this:

public function index()
 {
 $this-Paginator-settings = array(
 'Attraction' = array(
 'conditions' = array(
 'Attraction.deleted' = null
 ),
 'order' = array(
 'Attraction.sequence ASC',
 'Attraction.id ASC'
 ),
 'limit' = 15
 )
 );
 
 $attractions = $this-Paginator-paginate('Attraction');
 
 $this-set('attractions', $attractions);
 }


 But every time I load my index file, the list is sorted on ID.

My HTML sorting links above do work and I'm very happy with that:

div class=collapse navbar-collapse id=bs-example-navbar-collapse-1
 ul class=nav navbar-nav
 li?php echo $this-Paginator-sort('id', 'id'); ?/li
 li?php echo $this-Paginator-sort('name', 'naam'); ?/li
 li?php echo $this-Paginator-sort('show', 'zichtbaarheid'); 
 ?/li
 li?php echo $this-Paginator-sort('sequence', 'gewicht'); 
 ?/li
 /ul
 /div


So can anybody tell me if there's anything wrong with my order item in my 
paginator settings? ;)
Thx! 

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: jQuery sortable: how to update database?

2014-02-02 Thread Sam Clauw
Allright, that will be much easier to understand the whole AJAX and request 
happening! Last years, I've realy struggled with this and I think it will 
be a lot clearer for me now. Thank you!
To go back on my sorting problem: it isn't working yet. I dugged into 
CakePHP's Request Handling documentation and tried to catch the POST values 
from that AJAX request. The strange thing is that my controller seems to 
haven't catched a request at all! Here's my controller code:

class AttractionsController extends CoasterCmsAppController
{
public $components = array(
'RequestHandler'
);
...
public function beforeFilter() {
if ($this-RequestHandler-isAjax) {
echo 'Ajax';
} elseif ($this-RequestHandler-isPost) {
echo 'Post';
} elseif  ($this-RequestHandler-isGet) {
echo 'Get';
} else {
echo 'Damn, this string shouldn't be here!';
}
}
}

As you can guess, I always got the string Damn, this string shouldn't be 
here! outputted (instead of the Ajax echo). However, my javascript has 
no errors and I do get my data when I alert it in the succeed of my 
$.ajax. Is there something crucial that I'm forgetting? :)


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: jQuery sortable: how to update database?

2014-02-02 Thread Sam Clauw
Indeed Euromark, that was the reason it didn't work. I changed the notation 
too so I have an up-to-date program running;)
Salines  Euromark: thank you for helping me with this issue, I 
*realy*appreciate this! I can go further exploring CakePHP now! :)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


jQuery sortable: how to update database?

2014-02-01 Thread Sam Clauw
Hi there!

I've made a sortable table in my custom CMS system. You can drag and drop 
tr's so they have another position. 

This is the javascript in my sort.ctp file:

script
$(function() {
$('.sortable tbody').sortable({
axis: 'y',
scroll: true,
opacity: 0.5,
revert: 100,
cursor: 's-resize',
items: 'tr.grab',

// volledige breedte van tr behouden

helper: function (e, ui) {
ui.children().each(function () {
$(this).width($(this).width());
});
return ui;
},
stop: function (event, ui) {
var data = $(this).sortable('serialize');

// POST naar server ($.post of $.ajax)

$.ajax({
data: data,
type: 'POST',
url: '?php echo APP . 'CoasterCms' . DS . 'Lib' . DS . 
'sort.php'; ?'
});
}
}).disableSelection();
});
/script

Then, I've made a sort.php file and I've put it in the lib folder of my 
plugin (CoasterCms/Lib/sort.php). Here's the place where the magic should 
happen...
But it doesn't happen at all. The file currently looks like this:

?php

$db = $this-getDataSource();

$db-updateAll(
array( // fields
'Attraction.show' = 'N'
),
array( // conditions
'Attraction.id' = 3
)
);

?

Unfortunately, it does nothing. The baddest thing is that I can't test it 
on errors because I cannot reach the lib file by an url. Is there anybody 
who can guide me on the right way? How can I connect to my database and do 
some update actions on a specific model?

Thanks for helping me ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: jQuery sortable: how to update database?

2014-02-01 Thread Sam Clauw
Ow yes, you've got me on the right way! I've changed my .ctp file now:

script
$(function() {
$('.sortable tbody').sortable({
axis: 'y',
scroll: true,
opacity: 0.5,
revert: 100,
cursor: 's-resize',
items: 'tr.grab',

// volledige breedte van tr behouden

helper: function (e, ui) {
ui.children().each(function () {
$(this).width($(this).width());
});
return ui;
},
stop: function (event, ui) {
var data = $(this).sortable('serialize');

// POST naar server ($.post of $.ajax)

$.ajax({
data: data,
type: 'POST',
url: '*?php echo $this-here; ?*'
});
}
}).disableSelection();
});
/script

Then, I'll check on a submitted POST in my sort action and will handle the 
update.

One additional thing: where in Chrome developer tools can you see those 
ajax values? Elements, Network, Sources, ...? ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


CakePHP's naming conventions on hasMany through (The Join Model)

2014-01-31 Thread Sam Clauw
After struggling with this inconvenience for a couple of weeks now, I've 
decided to open en now topic here. A topic that can help me, but I'm sure 
it will help some others with this same problem too!

I wonder how I should name the tables, controllers and models of a hasMany 
through table (thus with additional fields) and it's coupled tables. I 
tried to stick on the CakePHP naming conventions as discribed in it's 
cookbook, but this constantly gave me some Object not found errors. For 
practical reason, I'll show you my problem with a many-words table. Perhaps 
that could be the reason of the problem? ;)

*Situation*

I have a fansite of a themepark and as you now, a themepark has many 
attractions. To ride an attraction, you must have a minimal height. 
Sometimes, small people can only ride it with an adult companion. But most 
of the time: you are allowed to ride the attraction because you just are 
tall enough ;)
Now I want to show the information of a specific attraction on my website. 
Name, content, photos, and so on. In addition to that information, I want 
to display my guests if they (or their kids) are tall enough to ride that 
attraction. It should appear like this way:

0m00 - 1m00: not allowed
1m00 - 1m30: allowed with an adult companion
1m30 - 1m90: allowed

*Database*

I have two tables that are representing two objects: attractions  
attraction_accessibilities. In this case, I'm 100% sure the database 
names are correct. Secondly, I should have another table between 
attractions and attraction_accessibilities. This table should contain:


   - an id specific for each record
   - a link to the id of the attractions table (attraction_id)
   - a link to the id of the attraction_accessibilities table 
   (attraction_accessibility_id)
   - the additional information like min-height and max-height

I *think* I should name that table 
attraction_accessibilities_attractions. It's a constriction of the two 
other tables, and I did it that way because CakePHP proposed it when you're 
making a HABTM association (
http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasandbelongstomany-habtm).

But unfortunately, when I do call it that way, I've never succeeded to link 
those models in my application together.

*Question*

Is there anybody who've had the same problem but found a solution for it? 
If yes: how should I name my database tables then and also important: how 
should I name my controller and model .php files?
Many thanks for the one who could help me and some other hopeless 
programmers ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Adding authentication to REST API server?

2014-01-31 Thread Sam
I would like to add authentication to a REST API server developed with 
cakephp. Are there any links or tips that I can use for a start?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Problem with year dropdown

2014-01-30 Thread Sam Clauw
Allright, thank you very much, that's the dropdown I was looking for!

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Problem with year dropdown

2014-01-28 Thread Sam Clauw
Is there nobody who can help me with this? Could it be possibile dat the 
datebase field type year isn't supported in CakePHP? If yes, what should 
I use instead? Varchar or...?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Problem with year dropdown

2014-01-23 Thread Sam Clauw
Hi guys!

I have a dropdown where you can choose an opening year of a themepark 
attraction.

Database

Column: opened
Type: year(4)
Null: no
Standard value: none

So far so good. Now I try to display a dropdown with year values between 
1954 (opening park) and the current year + 1.

edit.ctp

echo $this-Form-inputs(array(
'legend' = false,
'name' = array(
'label' = 'Name'
),
*'opened' = array(*
*'type' = 'year',*
*'label' = 'Year opening',*
*'dateFormat' = 'Y',*
*'minYear' = 1954,*
*'maxYear' = date('Y') + 1,*
*'empty' = 'Kies...'*
*),*
'show' = array(
'type' = 'radio',
'legend' = 'Show on website',
'options' = array(
'Y' = 'Ja',
'N' = 'Nee'
)
)
));

But here comes my first problem. The dropdown output is a list with values 
from 2034 to 0 and that's not the kind of options I want. When I change the 
type to date, the options do work great then. BUT then the selected value 
on edit is always 1970 (database says 1984). What could be the problem 
here?

My second problem occurs when saving the changes. Everytime I do so, I've 
got the error:

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 
 'field list'


I've debugged the request object and saw the following:

object(CakeRequest) {
params = array(
'plugin' = 'coaster_cms',
'controller' = 'attractions',
'action' = 'edit',
'named' = array(),
'pass' = array(
(int) 0 = '1'
)
)
data = array(
'Attraction' = array(
'name' = 'Boomerang',
'opened' = array(
'year' = '1984'
),
'show' = 'Y'
)
)
}

As you can see, the opened value send to the request object is an array. 
How can I change it so the data array have something like 'opened' = 1984 
in it?

Thanks for helping me ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


hasMany through: my neverending problem?

2014-01-22 Thread Sam Clauw
I have two tables: attractions  accessibilities. I want to display 
which people can go on which rides so I invented a new, joined table called 
accessibilities_attractions. Here's a visual representation of it:

https://lh6.googleusercontent.com/-nvhLQ93GqnY/Ut6PLdpucjI/ADU/ZHLBmBMJWB4/s1600/table.jpg
Data in table attraction (id - name) can be:

1 - Rollercoaster name
2 - Big Rollercoaster name
3 - Realy Big Rollercoaster name
4 - Biggest Rollercoaster ever seen name

Table accessibilities (id - name) has exactly 3 records:

1 - Forbidden
2 - Accessible with supervisor
3 - Accessible

Data in accessibilities_attractions (accessibility_id - attraction_id - 
min - max) can be:

Forbidden - Big Rollercoaster name - null - 110
Accessible with supervisor - Big Rollercoaster name - 110 - 130
Accessibile - Big Rollercoaster name - 130 - null
Forbidden - Biggest Rollercoaster ever seen name - Forbidden - null - 140
Accessibile - Biggest Rollercoaster ever seen name - 140 - null

As I am developping a CMS system, I've made a plugin called CoasterCMS. 
By this way, I implement a whole CMS system to CRUD the website elements of 
my favourite theme park (e.g. attractions, animals, events, ...)

To go further, I've created three models:

*Accessibility.php*

?php

class Accessibility extends CoasterCmsAppModel
{
public $hasMany = array(
'CoasterCms.AccessibilityAttraction'
);
}


*Attraction.php*

class Attraction extends CoasterCmsAppModel
{
...
public $hasMany = array(
'CoasterCms.AccessibilityAttraction'
);
...
}


*AccessibilityAttraction.php*

?php

class AccessibilityAttraction extends CoasterCmsAppModel
{
public $belongsTo = array(
'CoasterCms.Accessibility', 'CoasterCms.Attraction'
);
}


Now, I've created a model so I can insert, change and delete records in 
table accessibilities_attractions:

*AccessibilitiesAttractionsController.php*

?php

class AccessibilitiesAttractionsController extends CoasterCmsAppController
{
public $helpers = array('Html', 'Form', 'Session');
public $components = array('Session');

public function index()
{
debug($this-AccessibilityAttraction-find('all'));
}
...
}


And that's the point where my problem comes in. Every time I try to get the 
records via the find('all') method in my index action, I'm not getting an 
object at all:

Error: Call to a member function find() on a non-object 
 File: D:\Websites\BellewaerdeFun 2014\03 - 
 Online\app\Plugin\CoasterCms\Controller\AccessibilitiesAttractionsController.php
  
 Line: 10


I realy don't understand what goes wrong, because I ordered myself to stick 
on the CakePHP name conventions so nothing can go wrong...
Can anyone see what I'm doing wrong? After 2 days of searching, I cannot 
povide the solution on my own...

Thanks in advance :)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Does the choice of framework matter to ease of ajax dynamic front-end coding?

2014-01-20 Thread Sam
I have an upcoming project which may use lots of ajax dynamic front-end 
features. Does the choice of framework matter to ease of ajax dynamic 
front-end coding? I have never used ajax before, so I am kind of nervous at 
whether cakephp would be the right choice or if there is a simpler 
framework.

My understanding is that for ajax, it makes web services calls to the 
controller through sending the right URL and the controller returns the 
reply in json. Therefore, it should not really matter which framework is 
used because to the ajax, it just makes the right web service calls. Is my 
understanding correct? Thank you.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Does the choice of framework matter to ease of ajax dynamic front-end coding?

2014-01-20 Thread Sam
Thank you for the reply. I will need to do in-place editing of data tables. 
Some data tables displayed needs to be dynamic like stock prices updating 
in real-time but they need not be editable. I am hoping to find similar 
jquery (or even better, cakephp) projects which accomplish these tasks. 
Would you happen to know of any?

May I ask why CakePHP is simpler to work with ajax compared to other 
frameworks?

On Monday, January 20, 2014 11:15:20 PM UTC+8, José Lorenzo wrote:

 I think it does matter to certain degree, if the framework helps you 
 select the templates and layouts to use when requesting some content via 
 ajax or as another type (like json or xml), you end up saving a lot of 
 time. You're on the good place, then. CakePHP makes it extremely simple to 
 work with ajax applications and with building APIs.

 What are your requirements? Do you need any extra tips on how to use ajax 
 in cakephp?

 On Monday, January 20, 2014 3:58:41 PM UTC+1, Sam wrote:

 I have an upcoming project which may use lots of ajax dynamic front-end 
 features. Does the choice of framework matter to ease of ajax dynamic 
 front-end coding? I have never used ajax before, so I am kind of nervous at 
 whether cakephp would be the right choice or if there is a simpler 
 framework.

 My understanding is that for ajax, it makes web services calls to the 
 controller through sending the right URL and the controller returns the 
 reply in json. Therefore, it should not really matter which framework is 
 used because to the ajax, it just makes the right web service calls. Is my 
 understanding correct? Thank you.



-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Will combining cakephp with web templates like Smarty or Twig make front-end coding easier?

2014-01-20 Thread Sam
Cakephp is good for back-end work. Web templates like Smarty or Twig is 
used for front-end work. Will combining cakephp with web templates like 
Smarty or Twig make front-end coding easier? Is this advisable and has it 
been done before?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Will combining cakephp with web templates like Smarty or Twig make front-end coding easier?

2014-01-20 Thread Sam
I am doing some reading. Here is one thing that puzzles me. One advantage 
of web template engines is that they separate presentation and logic. The 
same can be said about MVC frameworks like Cakephp. Then, why do we combine 
both together since any single one can do the separation? Did I miss out 
something? What are the pros and cons? 

On Monday, January 20, 2014 11:45:33 PM UTC+8, José Lorenzo wrote:

 It helps to some extent, specially keeping the views safe from XSS 
 attacks. Some would argue that it does not make your views more readable, I 
 think it is a matter of preference. Here you have a CakePHP plugin for 
 working with Twig:

 https://github.com/WyriHaximus/TwigView

 On Monday, January 20, 2014 4:32:03 PM UTC+1, Sam wrote:

 Cakephp is good for back-end work. Web templates like Smarty or Twig is 
 used for front-end work. Will combining cakephp with web templates like 
 Smarty or Twig make front-end coding easier? Is this advisable and has it 
 been done before?



-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Pros and cons of Cakephp versus Laravel

2014-01-19 Thread Sam
Dear Cakephp gurus,

I have used cakephp in a past project (simple one) and I would like to 
continue using cakephp in a new project. There are some voices which 
advocate using Laravel which is an up-and-coming php framework. 

For experienced programmers who know something about both frameworks, could 
you tell me what are the pros and cons?

Since I use cakephp before, here are my comments about cakephp;
Pros
- It uses convention over configuration
I like this because I am forgetful. If the framework uses configuration 
over convention, I may miss out things to configure when things are changed 
or added to the code.

Cons
- It does quite a bit of magic in the background(can be good or bad) and 
loses flexibility in the process. If the programmer wants to do special 
things, he may have to fight cakephp.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Is it possible for a View to access another unrelated Model's data?

2014-01-19 Thread Sam
From what I understand from cakephp, a view is associated to a model and 
can only access the model's data. Is it possible for a View to access 
another unrelated Model's data? What I mean is whether it is possible for a 
view to access any database table's data, even if it is unrelated?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Is it possible to do watch window debugging of cakephp code?

2013-12-31 Thread Sam
Are there any debugger that allows one to trace our code on a watch window 
for cakephp?

Thank you.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Sample code for cakephp jquery edit-in-place tables

2013-12-13 Thread Sam
I would like to implement some excel-like tables for data entry using 
cakephp. Are there any sample code for cakephp that uses jquery to edit 
table?

Thank you very much.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Is it possible to retrieve webroot folder location in Javascript?

2013-10-29 Thread Sam
I am writing javascript with jquery currently. Is it possible to retrieve 
webroot folder location in Javascript? This will be good if webroot changes 
in future.

Thank you.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Is it possible to retrieve webroot folder location in Javascript?

2013-10-29 Thread Sam
I use the following ?php echo $this-webroot; ? to retrieve the webroot 
location in cakephp. I wonder how one can use Cakephp to retrieve webroot 
location in Javascript.

On Wednesday, October 30, 2013 7:08:30 AM UTC+8, Sam wrote:

 I am writing javascript with jquery currently. Is it possible to retrieve 
 webroot folder location in Javascript? This will be good if webroot changes 
 in future.

 Thank you.


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Updating data in real-time on table using Cakephp-DataTables

2013-10-29 Thread Sam
I stumbled onto a good tool that simplifies using jquery datatables on 
cakephp. (Demo website cakephpdatatables.cnizz.com). However, I would like 
to update my data in real-time because my data is live and changes by the 
minute. Can someone point me to some samples on the internet or some place 
to start for this feature? 

Thank you.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Can the same web app mix cakephp with non-cakephp code?

2013-10-11 Thread Sam
Is it possible for the same web app to mix cakephp with non-cakephp code? 
Some pages of a website can use cakephp and others use non-cakephp code. 
Can this be done?

Thank  you.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Can the same web app mix cakephp with non-cakephp code?

2013-10-11 Thread Sam
To move existing code into a vendor class, does the existing code need to 
follow certain format mandated by cakephp? Is it a complicated job to 
migrate code into a vendor class and reuse the vendor class?

Thanks.

On Saturday, October 12, 2013 12:06:58 AM UTC+8, Mike Karthauser wrote:


 On 11 Oct 2013, at 16:47, Sam light...@gmail.com javascript: wrote:

 Is it possible for the same web app to mix cakephp with non-cakephp code? 
 Some pages of a website can use cakephp and others use non-cakephp code. 
 Can this be done?


 yes it is. although you'd be be better moving your existing code into a 
 vendor class if you want to mix it into your cake stuff.



 Thank  you.

 -- 
 Like Us on FaceBook https://www.facebook.com/CakePHP
 Find us on Twitter http://twitter.com/CakePHP
  
 --- 
 You received this message because you are subscribed to the Google Groups 
 CakePHP group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to cake-php+u...@googlegroups.com javascript:.
 To post to this group, send email to cake...@googlegroups.comjavascript:
 .
 Visit this group at http://groups.google.com/group/cake-php.
 For more options, visit https://groups.google.com/groups/opt_out.


 
 Mike Karthäuser
 Director, Brightstorm Ltd.

 1, Brewery Court
 North Street
 Bristol
 BS3 1JS

 mi...@brightstorm.co.uk javascript:
 www.brightstorm.co.uk
 +44(0) 7939252144
 
  


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Can one use jquery instead of JsHelper?

2013-09-07 Thread Sam
Anyone knows why JSHelper will be removed in CakePHP 3.0? What is bad about 
it that caused it to be removed?

On Saturday, September 7, 2013 9:25:36 PM UTC+8, ravag...@gmail.com wrote:

 Guys, keep in mind that in CakePHP 3.0 there will be no JSHelper.

 https://github.com/cakephp/cakephp/pull/1012

 So I personally recommend to not rely on it, if you can.

 Sam, if you just started to use CakePHP and have not implemented JSHelper 
 yet, don't start with it.
 There's not much advantage over it except for convenience.

 You still can write performant  clean jquery code in combination with 
 CakePHP without using JSHelper.

 Greetings from Switzerland
 Marc

 Am Freitag, 6. September 2013 09:08:38 UTC+2 schrieb Simon Males:

 Yes you can. 

 JsHelper is just a shortcut to a few jQuery methods. 

 In particular I believe it's a convenient tool if you use jQuery UI. 

 On Fri, Sep 6, 2013 at 2:32 PM, Sam light...@gmail.com wrote: 
  Dear CakePHP experts, 
  
  I would like to use CakePHP and jQuery. There are sample source code 
  available with jQuery that I would like to use. But when I read CakePHP 
  documentation, the code with JsHelper is different from jQuery. Can I 
 simply 
  use jQuery and not JsHelper in CakePHP? 
  
  May I ask those who have used JsHelper, what are the advantages of 
 JsHelper 
  over jQuery? 
  
  Thank you. 
  
  -- 
  Like Us on FaceBook https://www.facebook.com/CakePHP 
  Find us on Twitter http://twitter.com/CakePHP 
  
  --- 
  You received this message because you are subscribed to the Google 
 Groups 
  CakePHP group. 
  To unsubscribe from this group and stop receiving emails from it, send 
 an 
  email to cake-php+u...@googlegroups.com. 
  To post to this group, send email to cake...@googlegroups.com. 
  Visit this group at http://groups.google.com/group/cake-php. 
  For more options, visit https://groups.google.com/groups/opt_out. 



 -- 
 Simon Males 



-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Can one use jquery instead of JsHelper?

2013-09-06 Thread Sam
Dear CakePHP experts,

I would like to use CakePHP and jQuery. There are sample source code 
available with jQuery that I would like to use. But when I read CakePHP 
documentation, the code with JsHelper is different from jQuery. Can I 
simply use jQuery and not JsHelper in CakePHP? 

May I ask those who have used JsHelper, what are the advantages of JsHelper 
over jQuery?

Thank you.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


  1   2   3   4   5   6   7   8   9   >