Pages

Monday, January 23, 2012

Changing CakePHP sessions settings

CakePHP manages its session inside CakePHP's /tmp directory. To manage cakephp session in wordpress integration add the following lines at the start of wp-config.php


$CAKE_SESSION_COOKIE = 'CAKEPHP';
ini_set('session.name', $CAKE_SESSION_COOKIE);
ini_set('session.cookie_path','app/tmp');
session_start();
?>




Integrating wordpress and cakephp

In one of my recent project I had a task of integrating Cakephp with Wordpress. The content pages had to be in Wordpress and other dynamic features were coming from CakePHP.

While trying to call Cakephp from wordpress or vice versa I was getting errors like "Fatal error: Cannot redeclare __()". These are mainly because of namespace conflict as Wordpress and Cakephp use some functions with same name.

CakePHP defines its functions in cake/basics.php. When Wordpress is integrated the file wp-includes/l10n.php gets included and has the same function names which results in fatal error.

The alternative is to add:

if ( !function_exists('__') ) :
// the function
endif;


for wordpress functions.

But I tried a different work around.
I kept wordpress and app folder of cakephp on root folder. To use same wordpress theme across the website I moved the header and footer.php outside of theme folder and kept in root.
So that the layout of cakephp also calls same header and footer.

Then I changed the .htaccess file to handle wordpress and cakephp related links separately.

This solved the fatal error issue and I was able to use wordpress and cakephp together in my website without any rework.