Tuesday, December 4, 2012

Re: Intégré php classique avec Cakephp

Hi Jellibi

You may wish to post the question in English, however, if Google Translate it doing it's job right, you want to integrate CakePHP with a regular PHP application.

I've done this for some of my older projects that are too large to migrate in one go.

The biggest hurdle is usually sharing the session between the regular PHP application, and the CakePHP application.  For this, you would be advised to have the application use the CakePHP session, and also authenticate via CakePHP.

I usually make a small modification to the app/webroot/index.php, to recognise that CakePHP is being used by an external application, and should not call the Dispatcher.

// near the bottom of app/webroot/index.php

/**
 * Do not dispatch if included by an external app
 * Could check if we could get away with just running the bootstrap,
 * except bootstrap may rely on previous defines.
 */
if (!defined('EXTERNAL_APP')) {
App::uses('Dispatcher', 'Routing');

$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(new CakeRequest(), new CakeResponse(array('charset' => Configure::read('App.encoding'))));
} else {
define ('DISABLE_DEFAULT_ERROR_HANDLING', 0);
}

Then, in some place code to here session checking is done in my classic PHP application, I do this:

    define('EXTERNAL_APP', true);
    include_once $_SERVER['DOCUMENT_ROOT'].'/cakphp/app/webroot/index.php';

    App::uses('ComponentCollection', 'Controller');
    App::uses('SessionComponent', 'Controller/Component');
    
    $componentCollection = new ComponentCollection();
    $Session = new SessionComponent($componentCollection);
    $return = $Session->id();
    if (!$return) {
    error_log('The session was not started:'.$Session->error());
    }
        
    $found = $Session->read('Auth.User');

I can then use $Session to read and write things to the session that can be read by the CakePHP application.

On the other hand, if you just want to use parts of the CakePHP framework with your classic PHP application (like using the Model framework), that functionality is not available (although I hope it will one day be possible).

Regards
Reuben Helms

On Tuesday, 4 December 2012 19:22:25 UTC+10, Jellibi Anas wrote:
comment peut on intégré une application php classique avec le framework cakephp

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: