Pages

Sunday, June 26, 2011

Using Pear Framework in Cakephp

1. Copy the pear in the venders directory in the root(there are 2 one in app folder as well)

If you wish to use that one copy cake/config/paths to app/config/paths and change the following line

/**
* Path to the vendors directory.
*/
if (!defined('VENDORS')) {
define('VENDORS', CAKE_CORE_INCLUDE_PATH.DS.app.DS.'vendors'.DS);
}

After copying Pear now you have the framework its time to copy components

2.copy the package needed in the pear directory

Now we will create a path for our Pear package so that Cake can easily access that

For that copy cake/config/paths.php to app/config.paths.php add an entry after venders definition as follows

"define ('PEAR',VENDORS.'Pear'.DS)";

This defines a constant for PEAR path...

Now we need to set that path in our include path for that in your boot_strap file mark an entry as

ini_set("include_path",PEAR.PATH_SEPARATOR.ini_get("include_path"));

so path is now set in "include_path".

Next we need our controller to recognize this so just before start of controller or view(as per requirement)enter the following line

App::import('Vendor','Words',array('file'=>'../vendors/Pear/Numbers/Words.php'));

That's all now you can create an object of class and use it as follows

$numberconverter=new number_words();

echo $numberconverter->towords($grandtotal);

If your view is going blank on creation of object check that the import link on top of controller or view is correct.

No comments:

Post a Comment