From The Blog

CakePHP: generate .po localization files using Shell

12 October 2013, in

 

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 the i18n command:

$ cd /var/www/mysite/app
$ ./Console/cake i18n

You'll see:



Post a Comment

CakePHP: change default model for a controller

30 November 2012, in

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 and you can't name the model class with name "Class" because it is a keyword in PHP, and you decided to change the model name to Classroom

Class ClassesController extends AppController {

$modelClass = 'Classroom';

....



Post a Comment

CakePHP: Get Client's IP Address

27 October 2012, in

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']



Post a Comment

Using Yahoo Weather API to get weather conditions in CakePHP2

2 June 2012, in

// import XML class
App::uses('Xml', 'Utility');

// your XML file's location

/*w is the code of the city, and u is the unit of temperature (c/f)
$xml = Xml::build('http://weather.yahooapis.com/forecastrss?w=615702&u=c');

$xml should contain the following data, where you can extract whatever you want from it



Post a Comment

Parsing XML easily in CakePHP 2

2 June 2012, in

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



Post a Comment

CakePHP 2 aggressive Security - continued

29 February 2012, in

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.

 



Post a Comment