webtechnick / CakePHP-Facebook-Plugin

CakePHP Facebook Plugin
http://facebook.webtechnick.com
445 stars 138 forks source link

Facebook::__construct() call session_start() before CakeSession #56

Closed dario1985 closed 12 years ago

dario1985 commented 12 years ago

Seem that Facebook SDK class breaks cakephp session behavior starting session outside of session component, because of CakePHP1.3 (2.0+ too?) starts session in SessionComponent::startup() after Components::initialize and Controller::beforeFilter() in Controller::startupProcess.

So, database and cake sessions dont work.

I temporary solved with a workaround patching ConnectComponent::initialize() to force Session start before of Facebook::__construct().

    function initialize(&$Controller, $settings = array()){
        $this->Controller = $Controller;
        if (!$this->Controller->Session->started()) {
            $this->Controller->Session->start();
        }
        $this->_set($settings);
        $this->FB = new FB();
        $this->uid = $this->FB->getUser();
    }
webtechnick commented 12 years ago

This isn't the case in 2.0. In fact, SessionComponent::start() has been removed from the API. So this is a 1.3 fix only. I appreciate the patch, if you wouldn't mind doing a pull request I'll make sure it makes it into the repository.

dario1985 commented 12 years ago

Thank you, I just sent the pull request.

Though I didnt found a better workaround for the issue

webtechnick commented 12 years ago

Thank you, merged into master. Thank you for your contribution.