Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session object not present in AuthComponent #3776

Closed
burzum opened this issue Jun 22, 2014 · 7 comments
Closed

Session object not present in AuthComponent #3776

burzum opened this issue Jun 22, 2014 · 7 comments
Assignees
Milestone

Comments

@burzum
Copy link
Contributor

burzum commented Jun 22, 2014

I'm trying to use the Auth component and get this error:

Fatal error: Call to a member function renew() on a non-object in C:\xampp\htdocs\cake3-test2\vendor\cakephp\cakephp\src\Controller\Component\AuthComponent.php on line 596

Call Stack
#   Time    Memory  Function    Location
1   0.0003  144192  {main}( )   ..\index.php:0
2   0.0169  1673976 Cake\Routing\Dispatcher->dispatch( )    ..\index.php:37
3   0.0235  2266696 Cake\Routing\Dispatcher->_invoke( ) ..\Dispatcher.php:91
4   0.0272  2396280 Cake\Controller\Controller->startupProcess( )   ..\Dispatcher.php:114
5   0.0356  3109416 Cake\Event\EventManager->dispatch( )    ..\Controller.php:491
6   0.0356  3109584 Cake\Event\EventManager->_callListener( )   ..\EventManager.php:237
7   0.0356  3109728 UserTools\Controller\Component\UserToolComponent->startup( )    ..\EventManager.php:266
8   0.0356  3109944 UserTools\Controller\Component\UserToolComponent->mapAction( )  ..\UserToolComponent.php:206
9   0.0356  3110072 UserTools\Controller\Component\UserToolComponent->login( )  ..\UserToolComponent.php:230
10  5.5199  5058264 Cake\Controller\Component\AuthComponent->setUser( ) ..\UserToolComponent.php:255

CakePHP commit id is bff4cb8, the code I'm testing this with is here https://github.com/burzum/cakephp-user-tools

@markstory markstory added this to the 3.0.0 milestone Jun 22, 2014
@markstory markstory self-assigned this Jun 22, 2014
@markstory
Copy link
Member

Looks like the issue is that AuthComponent::$session is set in the initialize() callback which is not set when AuthComponent is used by other components.

@ADmad
Copy link
Member

ADmad commented Jun 22, 2014

AuthComponent is being loaded on the fly here. You need to set the $session property too like you set $request and $response properties.

@markstory
Copy link
Member

It would be even better if AuthComponent's constructor did the right thing for you, and built a usable object. I will look into making that happen.

@ADmad
Copy link
Member

ADmad commented Jun 22, 2014

The components get request and response objects from controller instance which isn't available in it's constructor.

@ADmad
Copy link
Member

ADmad commented Jun 22, 2014

My bad, actually it can get the controller using collection's getController()

@burzum
Copy link
Contributor Author

burzum commented Jun 22, 2014

Ok, that fixed the original problem, but something still seems to be wrong:

Argument 1 passed to Cake\Controller\Component\AuthComponent::__construct() must be an instance of Cake\Controller\Component\ComponentRegistry, instance of Cake\Controller\ComponentRegistry given, called in C:\xampp\htdocs\cake3-test2\vendor\cakephp\cakephp\src\Controller\ComponentRegistry.php on line 99 and defined [ROOT\vendor\cakephp\cakephp\src\Controller\Component\AuthComponent.php, line 243]

Cake\Controller\Component\AuthComponent::__construct() - ROOT\vendor\cakephp\cakephp\src\Controller\Component\AuthComponent.php, line 243
Cake\Controller\ComponentRegistry::_create() - ROOT\vendor\cakephp\cakephp\src\Controller\ComponentRegistry.php, line 99
Cake\Utility\ObjectRegistry::load() - ROOT\vendor\cakephp\cakephp\src\Utility\ObjectRegistry.php, line 79
UserTools\Controller\Component\UserToolComponent::_getAuthObject() - ROOT\Plugin\UserTools\src\Controller\Component\UserToolComponent.php, line 424
UserTools\Controller\Component\UserToolComponent::login() - ROOT\Plugin\UserTools\src\Controller\Component\UserToolComponent.php, line 250
UserTools\Controller\Component\UserToolComponent::mapAction() - ROOT\Plugin\UserTools\src\Controller\Component\UserToolComponent.php, line 230
UserTools\Controller\Component\UserToolComponent::startup() - ROOT\Plugin\UserTools\src\Controller\Component\UserToolComponent.php, line 206
Cake\Event\EventManager::_callListener() - ROOT\vendor\cakephp\cakephp\src\Event\EventManager.php, line 264
Cake\Event\EventManager::dispatch() - ROOT\vendor\cakephp\cakephp\src\Event\EventManager.php, line 235
Cake\Controller\Controller::startupProcess() - ROOT\vendor\cakephp\cakephp\src\Controller\Controller.php, line 487
Cake\Routing\Dispatcher::_invoke() - ROOT\vendor\cakephp\cakephp\src\Routing\Dispatcher.php, line 110
Cake\Routing\Dispatcher::dispatch() - ROOT\vendor\cakephp\cakephp\src\Routing\Dispatcher.php, line 87
[main] - ROOT\webroot\index.php, line 37

CakePHP commit id b04a413

@markstory
Copy link
Member

Probably a missing use statement.

@markstory markstory reopened this Jun 23, 2014
markstory added a commit that referenced this issue Jun 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants