Reputation: 873
I'm trying to pass ACL settings from model directory to ACL plugin in bootstrap.
public function _initPlugins()
{
$frontController = Zend_Controller_Front::getInstance();
$frontController->registerPlugin(new Petra_Plugin_Layout_MultiLayout());
$frontController->registerPlugin(new Petra_Plugin_Controller_AclCheck(new Auth_Model_Acl_Acl()));
}
but autoloader cannot find class Auth_Model_Acl_Acl in Auth module. Is there any way to initialize MVC structure in bootstrap? Or maybe there is a better method to store ACL settings?
EDIT - more informations:
Bootstrap:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
private $view;
public function _initProperties()
{
$this->bootstrap("layout");
$layout = $this->getResource('layout');
$this->view = $layout->getView();
}
public function _initAutoload()
{
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace("Petra_");
// Added recently - not helping :(
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH . '/modules'
));
$test = new Auth_Model_Acl_Acl();
return $moduleLoader;
}
public function _initPlugins()
{
$frontController = Zend_Controller_Front::getInstance();
$frontController->registerPlugin(new Petra_Plugin_Layout_MultiLayout());
}
}
application.ini:
enter code here
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.params.displayExceptions = 0
resources.modules = ""
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
Directory structure:
/Application
/Config
application.ini
/layouts
default.phtml
/modules
/admin
...
/auth
/controllers
...
/models
/Acl
Acl.php
/views
...
boostrtrap.php
Upvotes: 0
Views: 2895
Reputation: 24009
I've had issues with the Module support in Zend Framework. Do you have a bootstrap for each of your modules? It can be blank, for example:
<?php
class Auth_Bootstrap extends Zend_Application_Module_Bootstrap {}
The file should be Application/modules/auth/Bootstrap.php
Upvotes: 1
Reputation: 1977
I've written a 3-part tutorial on my blog, which does exactly what you want, and you'll have an easy control over the resources on the website. Its stored in XML, and you just need to provide "where" to get the current user role information.
try reading them at:
http://wolfulus.wordpress.com/
Tell me what you think, and any suggestions are welcome too.
Upvotes: 0
Reputation: 3220
You define a resources autoloader 'Zend_Application_Module_Autoloader' to find classes without a namespace and from the directory APPLICATION_PATH . '/modules'
The autoloader has an array of resources:
array(8) { ["Model_DbTable"]=> string(74) "/path/to/application/modules/models/DbTable" ["Model_Mapper"]=> string(74) "/path/to/application/modules/models/mappers" ["Form"]=> string(65) "/path/to/application/modules/forms" ["Model"]=> string(66) "/path/to/application/modules/models" ............ }
The resource autoloader find this class 'Auth_Model_Acl_Acl' as a resource of 'Auth' or 'Auth_Model' or 'Auth_Model_Acl' or Auth_Model_Acl_Acl'. These are not a valid resources. The autoloader will return false at line 177 class 'Zend_Loader_Autoloader_Resource'.
The following will auto load your model class:
$moduleLoader = new Zend_Application_Module_Autoloader(array( 'namespace' => 'Auth', 'basePath' => APPLICATION_PATH . '/modules/auth' ));
A solution (Create your custom autoloader) : Add the following after the autoloader. You can change 'Petra_Autoloader' to any other class you want.
$autoloader->pushAutoloader(new Petra_Autoloader, '');
Create a class that implements Zend_Loader_Autoloader_Interface
class Petra_Autoloader implements Zend_Loader_Autoloader_Interface{ public function autoload($class) { // your implementation to load the class } }
Bootstrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { //............ public function _initAutoload() { $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace("Petra_"); $autoloader->pushAutoloader(new Petra_Autoloader, ''); $test = new Auth_Model_Acl_Acl(); return $moduleLoader; } //.............. }
Hope this helps
Update
In your application.ini you have the appnamespace = "Application". Auto loading a model class 'Default_Model_MockupsElementsTypes' from APPLICATION_PATH "/models' will fail, because the auto loader is looking for classes starting with 'Application'. Class name 'Application_Model_MockupsElementsTypes'.
In my test machine I have this and it worked fine:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { //............ public function _initAutoload() { $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace("Petra_"); $autoloader->pushAutoloader(new Petra_Autoloader, ''); $test2 = new Application_Model_DbTable_Guestbook; // classes loaded with the autoloader $test = new Auth_Model_Acl_Acl(); return $moduleLoader; } //.............. }
Upvotes: 1
Reputation: 520
In my project I made all models available with the line below in application.ini:
includePaths.models = APPLICATION_PATH "/models/DbTable"
Upvotes: 0
Reputation: 10939
Try this, make sure that you have already bootstrapped db and frontController
public function _initPlugins()
{
$this->bootstrap('db');
$this->bootstrap('frontController');
$frontController = $this->getResource('frontController');
$frontController->registerPlugin(new Petra_Plugin_Layout_MultiLayout());
$frontController->registerPlugin(new Petra_Plugin_Controller_AclCheck(new Auth_Model_Acl_Acl()));
}
EDIT: ok, how I do this in my apps is from my INI file:
[production]
; PHP SETTINGS
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
phpSettings.session.auto_start = 0
; SET UP DEFAULT RESOURCES
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/modules/default/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.layout.layoutPath = APPLICATION_PATH "/modules/default/layouts/scripts"
resources.layout.layout = "layout"
resources.layout.viewSuffix = php
resources.layout.pluginClass = "Perinatal_Controller_Plugin_LayoutSwitcher"
resources.frontController.controllerDirectory = APPLICATION_PATH "/modules/default/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.plugins.acl = "Perinatal_Controller_Plugin_Acl"
resources.frontController.plugins.themer = "Perinatal_Controller_Plugin_Themer"
resources.frontController.plugins.mail = "Perinatal_Controller_Plugin_Mail"
...
This is where i load up my themes layouts mail and acl settings
Upvotes: 0
Reputation: 14184
It largely depends upon where the Auth_Model_Acl_Acl
class is stored.
If it resides on the include path, perhaps in library/Auth/Model/Acl/Acl.php
, then you just need to register the namespace with the autoloader. In configs/application.ini
, just add:
autoloadernamespaces[] = "Auth_"
If the class resides in a module called auth, so that it resides in the file application/modules/auth/model/Acl/Acl.php
, then you just need to be sure that you have initiated the modules correctly, typically with the following in configs/application.ini
:
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =
This will fire up the module application resource plugin which in turn registers a module-autololoader which should map correctly for your Acl class.
However, if this class wants to reside someplace else - like at the application root or in another module - then you have to set up some other resource autoloader mappings.
Upvotes: 4