Using the bake command, cakephp will read all your source files and it will extract all the text to translate. So it’s very important that you write the string in the i18n function and don’t pass just variables. For example to extract the text, using the command line go to you app directory, and execute … Continue reading CakePHP: generate .po localization files using Shell
Tag: cakephp
In many cases when we want to formulate complex queries, that need joins between tables, we can still add joins on the fly by adding it to the call of find $students_of_grade = $this->User->find('list',array( 'fields'=>array('UserData.user_id'), 'joins'=>array( array( … Continue reading CakePHP joining tables
By default a CakePHP controller uses a model with singularized name, for example a controller with name Students will use by default a model named Student, But if you want or have to change the default model for a controller you can set it using $modelClass member attribute for example for a controller named ClassesController … Continue reading CakePHP: change default model for a controller
In CakePHP it is pretty easy to change the way that users reach to a specific action to another beautiful URL for ex: you may have a page that contains category details, and users reach to it via: http://domain.com/categories/view/id controller is "categories", action is "view", and it takes 1 parameter id and you may want … Continue reading CakePHP: Custom routes and pagination
in CakePHP 1.x Through the RequestHandler Component: RequestHandlerComponent::getClientIp(); in CakePHP 2.x RequestHandler::getClientIp() is deprecated, so you can use the CakeRequest object $this->request->clientIp(); of course you can still use the server variable $_SERVER['REMOTE_ADDR']
By default, the maximum number of fetched rows on pagination is set to 100 rows, whatever number of rows higher than it you assign it to the "limit", property, it will not affect, but you can adjust it as part of the pagination options: public $paginate = array( // other keys here. 'maxLimit' => 10 ); … Continue reading CakePHP max number of fetched row on pagination
I observed that CakePHP treats tinyint fields as boolean (true/false) , but after investigation found that: if you set the data type for a field to tinyint with length of 1, then CakePHP will treat it as boolean. So I changed it to tinyint(2), That's weird about CakePHP
It is very easy to parse XML in CakePHP , here is an example in CakePHP v2 // import XML Utility class App::uses('Xml', 'Utility'); // your XML file's location $xml1 = Xml::build('http://url-of-XML'); $xml2 = Xml::build('http://http://url-of-XML', array('return' => 'simplexml')); // $xml now is a instance of SimpleXMLElement // New method using DOMDocument $xml3 = Xml::build('http://url-of-XML', array('return' … Continue reading Parsing XML easily in CakePHP 2
CakePHP 2.0 has another aggressive security which is shown clearly when trying to make an ajax request to an action via method POST, it fires security error that says "Request is blackholed due to auth". The Solution to disable this aggressive validation for this action to set security attribute $validatePost to false. property SecurityComponent::$validatePost Set … Continue reading CakePHP 2 aggressive Security – continued
CakePHP has had CSRF protection since 1.2. For 2.0 the existing CSRF has a new more paranoid mode, and is its own standalone feature. By default a new CSRF token is generated for each request, and each token can only be used one. If a token is used twice, it will be blackholed. Sometimes, this … Continue reading CakePHP 2 Aggressive Security