Open t1mmen opened 10 years ago
I guess you would need to disable Crud for the opauth plugin - CRUD don't have any build in way of doing this easily.
Maybe you can do something like this in your AppController beforeFilter
:
if ($this->request->plugin === 'Opauth') {
$this->Components->disable('Crud');
}
Wow, thanks for the quick responses @jippi and @jose_zap :)
It doesn't appear to make a difference, though:
//AppController.php
public function beforeFilter() {
if ($this->request->plugin === 'Opauth') {
$this->Components->unload('Crud'); // tried with Crud.Crud scope as well,
$this->Components->disable('Crud'); // this doesn't do it either, I guess..
debug(CakePlugin::loaded());
}
parent::beforeFilter();
}
// Shows:
array(
(int) 0 => 'Crud',
(int) 1 => 'Opauth'
)
.. and the same page as before ("No model loaded in the Controller by the name "Opauth". Please add it to $uses.")
It's fine that the plugin is loaded, the component should just be disabled for Opauth.
If the component is disabled, then it should not get any events from the cakephp controller, and thus not try to hijack the request into a CRUD controller.
Is the debug info shown before the error is raised?
Do you call $this->Crud->execute() anywhere manually?
You can also try to unload it and unset($this->Crud)
$this->Components->disable('Crud')
$this->Crud->execute()
anywhere. public function beforeFilter() {
if ($this->request->plugin === 'Opauth') {
$this->Components->unload('Crud'); // tried with ->disable too, no change.
$this->Components->unload('Crud.Crud'); // just to be sure..
unset($this->Crud);
debug(CakePlugin::loaded());
}
parent::beforeFilter();
}
My error.log:
2014-03-06 13:48:49 Error: [CakeException] No model loaded in the Controller by the name "Opauth". Please add it to $uses.
Request URL: /myapp/auth/github
Stack Trace:
#0 /Users/timmstokke/Dropbox/www/myapp/Plugin/Crud/Controller/Component/CrudComponent.php(614): CrudComponent->_setModelProperties()
#1 /Users/timmstokke/Dropbox/www/myapp/Plugin/Crud/Controller/Component/CrudComponent.php(751): CrudComponent->getSubject()
#2 /Users/timmstokke/Dropbox/www/myapp/Plugin/Crud/Controller/Component/CrudComponent.php(728): CrudComponent->_loadListener('RelatedModels')
#3 /Users/timmstokke/Dropbox/www/myapp/Plugin/Crud/Controller/Component/CrudComponent.php(169): CrudComponent->_loadListeners()
#4 [internal function]: CrudComponent->initialize(Object(OpauthController))
#5 /Users/timmstokke/Dropbox/www/myapp/vendor/pear-pear.cakephp.org/CakePHP/Cake/Utility/ObjectCollection.php(132): call_user_func_array(Array, Array)
#6 [internal function]: ObjectCollection->trigger(Object(CakeEvent))
#7 /Users/timmstokke/Dropbox/www/myapp/vendor/pear-pear.cakephp.org/CakePHP/Cake/Event/CakeEventManager.php(247): call_user_func(Array, Object(CakeEvent))
#8 /Users/timmstokke/Dropbox/www/myapp/vendor/pear-pear.cakephp.org/CakePHP/Cake/Controller/Controller.php(674): CakeEventManager->dispatch(Object(CakeEvent))
#9 /Users/timmstokke/Dropbox/www/myapp/vendor/pear-pear.cakephp.org/CakePHP/Cake/Routing/Dispatcher.php(182): Controller->startupProcess()
#10 /Users/timmstokke/Dropbox/www/myapp/vendor/pear-pear.cakephp.org/CakePHP/Cake/Routing/Dispatcher.php(160): Dispatcher->_invoke(Object(OpauthController), Object(CakeRequest), Object(CakeResponse))
#11 /Users/timmstokke/Dropbox/www/myapp/app/webroot/index.php(99): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#12 {main}
Can you come by the #FriendsOfCake IRC channel ? easier to debug live :)
Absolutely! I'll come by shortly, thanks :)
Thanks to @jippi, I got it working by:
public $components = array(
//....
'Crud.Crud' => array(
'enabled' => false, // ADDED THIS
'actions' => array(
'index', // 'view', 'edit', 'delete', 'add'
),
'listeners' => array( // <- new
'api' => 'Crud.Api'
)
),
);
AppController's beforeFilter looks like:
public function beforeFilter() {
// if ($this->request->plugin != 'Opauth') {
$this->Components->enable('Crud');
$this->Crud->initialize($this);
// }
parent::beforeFilter();
}
@jippi also noticed https://github.com/uzyn/cakephp-opauth/blob/master/Controller/OpauthController.php#L9 is missing parent::beforeFilter();
, meaning my beforeFilter in AppController is never run when inside the opauth plugin.
Re: https://twitter.com/t1mmen/status/441512918950359040
When FriendOfCake's Crud plugin is loaded, Opath no longer works, giving the error message:
"No model loaded in the Controller by the name "Opauth". Please add it to $uses."
.. when trying to access
http://localhost/myapp/auth/github
. This works as expected when the Crud plugin is not setup in $components.I installed Opauth using Composer:
And my
bootstrap.php
has this part added:My directory tree looks like this: https://www.dropbox.com/s/4pzmcpcqv75aqdn/Screenshot%202014-03-06%2013.03.21.png