Some interesting findings from web-dev land…
If you get this error:
1Warning: Warning (2): preg_match() [<a href=’function.preg-match’>function.preg-match</a>]: Delimiter must not be alphanumeric or backslash in [/var/www/vhosts/h2oservices.com/httpdocs/cake/libs/model/model.php, line 2611]
When trying to use a custom validation rule, make sure the method visibility is set to public.
So this should work:
123public function myCustomValidateRule(){
// Custom validation code
}
It seems protected visibility works on some versions of [...]
If you have fields that don’t exist in your table schema and you want to submit those to an action that is protected by the Security component. You can tell the component to ignore (and therefore not black hole/404 your request) the field(s) using its $disabledFields attribute.
In this example I’m ignoring the security_code (captcha) field, [...]
Just managed to count another table using a model virtual field, obviously preserving the association with the sub query conditions.
So in my ProductTemplate model I have this:
123var $virtualFields = array(
‘page_count’ => ‘SELECT COUNT(*) FROM pages as Page WHERE Page.product_template_id = ProductTemplate.id’
);
The nice thing about this is you can use the field with [...]
You can save has and belongs to many models in CakePHP (v1.3.4) whilst adding additional data to the join table, in a single operation.
In this example I’m saving Users that HABTM Videos. The users_videos join table has an order column.
Firstly add the ‘with’ parameter to the join, you can add the ‘order’ parameter too [...]
I’m in the situation where most of my CMS components are extensible CakePHP plugs.
I’ve just started to use the CakeDC migrations plugin (been meaning to for a long time as I always loved Rails migrations).
I had previously automated the insertion of plugin ACO node records using a Bash script that chugged through a stack [...]
If you’re using the CakePHP Containable behavio(u)r and trying to query with conditions across a Has and Belongs To Many association, you need to specify you wish to contain the dynamically bound model records, before you do the actual find.
Here’s one example from the book that doesn’t work with Containable:
123456$this->Recipe->bindModel(array(’hasOne’ => array(’RecipesTag’)));
$this->Recipe->find(’all’, array(
‘fields’ [...]
I was experiencing this issue with some larger file uploads using the CakePHP Media plugin.
https://bugs.webkit.org/show_bug.cgi?id=5760
I added this to the virtual host declaration in my Apache config file to fix it:
123456<VirtualHost x.x.x.x:x>
# Prevent Safari from hanging on uploads
BrowserMatch Safari nokeepalive
</VirtualHost>
If you’re trying to use the CakePHP Media plugin with 1.3 (I’m running RC3) and you get this error when deleting an attachment:
1Call to undefined method Folder::ls() in /path_to_app/app/plugins/media/models/behaviors/media.php on line 277
ls() has been deprecated in favour of read(), change line 277 of /path_to_app/app/plugins/media/models/behaviors/media.php to:
1list($versions, ) = $Folder->read();
All should work fine thereafter ;]
I wasn’t having much luck with the example given in the CakePHP book for a Has and Belongs To Many relationship with a single option select menu in the view.
Anyway overriding the element type does the trick:
1<?php echo $form->input(’ResellerField’, array(’multiple’ => false)) ?>
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();