To create a helper which name consists of more than one word use the following naming convention:
12345678910111213# Helper name: MyHelper
# File name
app/views/helpers/my_helper.php
# Class name (Camel Case)
class MyHelper extends AppHelper
# In Controller (Camel Case)
var $helpers = array(’MyHelper’);
# In View (Camel Back):
$myHelper->method();
Quick refresher for my own records. CakePHP ACL component console commands:
1234567891011121314151617181920212223# View ACO tree
cake acl view aco
# Create root ACO container – in this instance site
cake acl create aco root site
# Create ACO controller node – in this instance the products controller
cake acl create aco site Products
# Create ACO controller action node – in [...]
This is quite handy if you’re working in a team and you don’t want the designer/client poking about in the controllers to set page titles. You can set them in the view using this code:
UPDATE thanks for bringing the v1.3 change to my attention JT.
12345v1.3
<? $this->viewVars[’title_for_layout’] = ‘My page title’ ?>
v1.2
<? $this->pageTitle = ‘My page [...]
I’ve been using the containable behavio(u)r in CakePHP along with the $recursive = -1 property in my models to cut down on the amount of SQL querying going on.
I needed to specify a second level recursion on one of my associated models and managed it by doing this:
12345$this->paginate[’Invoice’][’contain’] = array(
‘Order’ => ‘OrderedProduct’,
[...]
If you use the CakePHP Auth component and you need some conditions for users attempting to login, you can set this attribute/property in the Auth object:
1$this->Auth->userScope = array(’User.status’ => 1);
The userScope attribute behaves pretty much like an Active Record find condition definition.
So in the above example, only users with a status of 1 (active) can [...]
Tried to do a schema snapshot of my db today (cake schema generate) to throw in SVN. I’d added an enum column to one of my tables and it threw this error:
1Notice: Schema generation error: invalid column type enum(’flat_fee’,'per_unit’) does not exist in DBO in /vhosts/site.com/accounts/cake/libs/model/schema.php on line 475
Enum must be too old-school and crusty [...]
You can display plugin layouts (and views) from another plugin by doing this in your controller.
This example is for a layout:
1234$view_paths = Configure::read(’viewPaths’);
array_unshift($view_paths, (APP.’plugins’.DS.’plugin_name’.DS.’views’.DS));
Configure::write(’viewPaths’, $view_paths);
$this->layout = ‘layout_name’;
You can place this code inside a wrapper method in your plugin app controller to make it accessible from other controllers within the same plugin too ;] Obviously [...]
Woo hoo! It’s possible to override CakePHP plugin views just like in Rails using the Engines plugin. Documentation on how to do it is a bit thin on the ground though.
Say you created a CakePHP plugin called ‘cms’ and you had a plugin controller called ‘pages’ inside the cms plugin. Just place the views you [...]