cakePHP

How to include PEAR libraries with CakePHP?

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’));

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

cakephp Deprecated: PHP 5.3 Wamp

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

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

CakePHP – Bake Process

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
Continue Reading…

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Ubuntu Hardy Heron, CakePHP Setting in Virtual Host Environment

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
NameVirtualHost 192.168.1.100:80

<VirtualHost 192.168.1.100:80>
ServerName cakeapp
DocumentRoot /var/www/cakeapp
</VirtualHost>

(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] </IfModule>

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

CakePHP: Multi-validatable Behavior

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(){
$this->User->setValidation(‘login’);
}

function changepassword(){
$this->User->setValidation(‘changepassword’);
}

For more info visit CakePHP Bakery

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Configuring CakePHP in localhost

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.
Continue Reading…

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

cakePHP, codeIgniter: simple method to display array data

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
Continue Reading…

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

cakePHP: Static page handling tips

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.

page1.ctp

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

page2.ctp

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

Continue Reading…

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

cakePHP: Session enabled messages using Session->setFlash

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

Continue Reading…

Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

CakePHP: Parsing RSS feed in Simple Steps

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

<?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(){
		App::import('Xml');
		$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




Share it onShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn
Kurinchi Calendar
July 2017
M T W T F S S
« Apr    
 12
3456789
10111213141516
17181920212223
24252627282930
31