Reputation: 15692
I wrote an Auth plugin to check if the user is logged in. No unlogged user should be able to visit anything in the app except the login page.
So I have this in the file application/modules/user/plugins/Auth.php
:
class User_Plugin_Auth extends Zend_Controller_Plugin_Abstract {
public function preDispatch(Zend_Controller_Request_Abstract $request) {
if (Zend_Auth::getInstance()->hasIdentity()
|| $this->getRequest()->getActionName() == 'login') return;
$request->setModuleName('user');
$request->setControllerName('auth');
$request->setActionName('login');
}
}
Then I made this in the application.ini
:
pluginPaths.User_Plugin = APPLICATION_PATH "/modules/user/plugins/"
resources.frontController.plugins[] = "User_Plugin_Auth"
However, no matter how I move the Auth.php
file and no matter the name, I always get Fatal error: Class 'User_Plugin_Auth' not found
. Please help me, I have wasted more than one hour on this and it's frustrating.
Upvotes: 0
Views: 120
Reputation: 3331
I think the problem is to do with the filename. I would try creating copies of the files in these locations
application/modules/user/plugins/User_Plugin_Auth.php
application/modules/user/plugins/User/Plugin/Auth.php
naturally you only need one of them, so delete the others once you have found the one that works.
If that doesn't help that the syntax I have in my config (Fam is just the codename of the project)
resources.frontController.plugins.layout = "Fam\Controller\Plugin\Layout"
resources.frontController.plugins.route = "Fam\Controller\Plugin\Route"
as pointed out in comments that is php 5.3 - this should work in older versions assuming include paths are configured
resources.frontController.plugins.layout = "Fam_Controller_Plugin_Layout"
resources.frontController.plugins.route = "Fam_Controller_Plugin_Route"
which maps to the files in my library, eg
APPLICATION_PATH "/../library/Fam/Controller/Plugin/Layout.php"
For reference in this project my Zend files are in
APPLICATION_PATH "/../library/Zend"
so adjusting the files to be in the relative place should do the trick
is your autoloader configured? I have autoloaderNamespaces.0 = "Fam"
you might need something like
autoloaderNamespaces[] = "User_"
resources.frontController.plugins.UserAuth = "User_Plugin_Auth"
Upvotes: 1