Kurinchi Blogger Scribbles …

Posts Tagged ‘cakePHP’

Oct 10

How to include PEAR libraries with CakePHP?

Last updated: October 8th, 2009

Suggested solutions from other sites:
1) Modify /config/paths.php
2) Create separate php.ini settings file with the path to PEAR library
3) Modify the app_controller.php with the PEAR path settings

My preference is to add the PEAR library to the “vendors” folder and to modify the app_controller to have the PEAR path included through it.

if( file_exists(VENDORS.’Pear’)){
ini_set(‘include_path’, ini_get(‘include_path’) . PATH_SEPARATOR . PEAR);

Above solution suggested at CakePHP’s trac

Depending on the library that you want to get included in the programs, add the library to the respective view

App::import(‘vendor’, ‘XML_Feed_Parser’, array(‘file’ => ‘../vendors/pear/XML/Feed/Parser.php’));

Sep 01

cakephp Deprecated: PHP 5.3 Wamp

Last updated: September 2nd, 2009

Error message
cakephp Deprecated: Assigning the return value of new by reference is deprecated
You will see the above error message when you try to configure cakePHP framework using a Wamp Server installation and set the debug parameter as in

Configure::write(‘debug’, 2);

Cause: CakePHP is not PHP 5.3 ready unlike the latest version of Zend framework.

Remedy: Try downloading older version of PHP – e.g. PHP 5.2.9

Aug 11

CakePHP – Bake Process

Last updated: August 10th, 2009

CakePHP Steps involved in Baking Scripts:

i) Setup cakephp by ensuring that there is no warning message in the index page after initial installation. (for this you need to change salt value in /app/config/core.php, enable /app/config/database.php)

ii) Create a database and a user for the database. After this apply the database configuration parameters to /app/config/database.php

If you are running the bake for the first time, it will ask you to create database configuration for the first time.

iii) Ensure that the path or the environment variable is set with access to PHP, MySQL executables

c:/> PATH or $ echo $PATH

Aug 05

Ubuntu Hardy Heron, CakePHP Setting in Virtual Host Environment

Last updated: July 30th, 2009

If you are to setup CakePHP in a virtual hosting environment, we need to ensure that the DocumentRoot is setup correctly. Based on the experience I have had I thought to list down the virtual host setting and cakephp .htaccess setting files.

root@myserver:/etc/apache2/conf.d# cat vhosts.conf

ServerName cakeapp
DocumentRoot /var/www/cakeapp

(Note that there is no ending forward slash after /var/www/cakeapp. If there had been one, it might cause a problem if the /var/www/cakeapp/app/config/routes.php is not configured correctly indicating a never ending loop in resolving domain name)

root@myserver:/etc/apache2/conf.d# cat /var/www/cakeapp/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]

Jul 21

CakePHP: Multi-validatable Behavior

Last updated: August 5th, 2009

Consider the following scenario where we have a database table:users and that we need carry the validations for the following forms
i) Login
ii) Change password
iii) Add/Edit user records
iv) Forgot password

You can either write separate controllers and have each controller call a model based on table: users to validate each input field or use the same user model to carry out different validations which sounds logical.

It is easy to carry out different validations in a cakephp model by using the Multi-validatable Behavior by having different validation sets for different testing conditions.

Key things to note here …

i) Download the code for Multivalidatable Behavior and have it placed under /models/behaviors/ folder

ii) In the model where you want to have multi validation, you need to include multivalidatable behavior like
var $actsAs = array(“Multivalidatable”);

iii) Add validation rulesets array like
var $validationSets = array(‘login’ => array(‘name’=>array(‘rule’=>’alphanumeric’)),
‘changepassword’ => array(‘password’=>array(‘rule’=>’notEmpty’))

iv) In the controller where you want to apply the validation rule set, you need to add the respective validation like

function login(){

function changepassword(){

For more info visit CakePHP Bakery

Jul 05

Configuring CakePHP in localhost

Last updated: July 9th, 2009

Quick and easy steps

Grab a copy of cakePHP from cakephp.org website

You can either create the new cakephp website in the root (http://localhost/) or by adding it as a subfolder (http://localhost/mycakesite/)

If you create it as a subfolder, then configure the appropriate path settings for linking images in the web pages.

Jun 14

cakePHP, codeIgniter: simple method to display array data

Last updated: June 17th, 2009

var_dump(), print_r() are commonly used functions to display data that is passed across controllers or views when playing in MVC frameworks. As the printed data stretches as a long string, it may be difficult to manipulate the resultset in most cases.

When programming in CakePHP or CodeIgniter or other MVC frameworks when you do not want to turn on the debugger routine and want to have a clean display of Array Data you can try adding a simple method in the Controller (appController in cakePHP) as follows

Jun 12

cakePHP: Static page handling tips

Last updated: June 17th, 2009

You can create static pages in cakePHP by adding .ctp files under /app/views/pages folder and can access it using the URI http://sitename/pages/pagename.ctp.

Try creating two files page1.ctp and page2.ctp and add those files under /app/views/pages folder.


<h1>Page 1</h1>
<p>Static Content for page 1 goes here</p>


<h1>Page 1</h1>
<p>Static Content for page 1 goes here</p>


Jun 09

cakePHP: Session enabled messages using Session->setFlash

Last updated: June 9th, 2009

There are different ways to flash or publish the messages for a user action. Usability plays a major role in determining how the navigation pattern for a web application takes place.

  • publishing the outcome of user action on the same page
  • designing a single page to flash all success, error, warning, notice level messages
  • designing a separate page for each message that gets published for the user


Jun 05

CakePHP: Parsing RSS feed in Simple Steps

Last updated: June 8th, 2009

How to read RSS feeds (XML file) and display contents in CakePHP?

Parsing an XML feed can be done in simple steps as follows in CakePHP …

CakePHP Controller: /app/controllers/rss_controller.php

*	CakePHP Controller to parse XML file
class RssController extends AppController{
	var $name = "Rss";
	// As the RSS will not currently use a database
	var $uses = array();
	var $feed_url = "http://kurinchilamp.kurinchilion.com/feed";
	var $rss_item = array();
	function index(){
		$parsed_xml =& new XML($this->feed_url);
		// xml to array conversion
		$this->rss_item = $parsed_xml->toArray();
		$this->set('data', $this->rss_item['Rss']['Channel']['Item']);

CakePHP View: /app/views/rss/index.ctp

Valid HTML 4.01 Strict  Valid HTML 4.01 Strict