Doug Wolfgram
Doug Wolfgram

Reputation: 2126

Zend Bootstrap How do I autoload a model?

I have an auth plugin working. I am trying to add ACL to it according to the excellent video series at http://www.youtube.com/watch?v=b6qsSnLfcmE&feature=relmfu.

My problem is that when I try to register the model in Bootstrap so that I can pass the instance to the plugin, I get a server 500 error. My bootstrap looks like this...

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAutoload()
{
    $modelLoader = new Zend_Application_Module_AutoLoader(array(
        'namespace' => '',
        'basePath'  => APPLICATION_PATH));

    $acl = new Model_SystemAcl;
    $auth = Zend_Auth::getInstance();

    $fc = Zend_Controller_Front::getInstance();
    $fc->registerPlugin(new Plugin_AccessCheck($acl,$auth));

    return $modelLoader;
}

}

It is the line:

$acl = new Model_SystemAcl;

That is causing the problem. If I comment it out (and the $acl parameter that is passed) it works fine. It appears as though somehow my system is not configured properly to load models. This is the entire Bootstrap shown in the tutorial btw. Perhaps there is something in Application.ini I need?

EDIT: Yes, SystemAcl.php exists and is in [applicationdir]/models

Upvotes: 0

Views: 549

Answers (4)

Tim Fountain
Tim Fountain

Reputation: 33148

Based on your setup the filename of your class should be SystemAcl.php, not Model_SystemAcl.php.

Upvotes: 1

Maks3w
Maks3w

Reputation: 6429

This is a full example for load models from the application namespace "Application"

$resourceLoader = new Zend_Loader_Autoloader_Resource(
    array(
         'basePath'  => APPLICATION_PATH,
         'namespace' => 'Application',
    )
);
$resourceLoader->addResourceType('model', 'models/', 'Model');

$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->pushAutoloader($resourceLoader);

Upvotes: 1

MazB
MazB

Reputation: 151

if it is in application/models then i would have thought the script should be Models_SystemAcl not Model_SystemAcl (no 's'). Saying that, it is better to use plugins in the long run, rather than sticking this sort of stuff in the bootstrap. Those tutorials are good though :)

Upvotes: 0

Ademir Mazer Jr - Nuno
Ademir Mazer Jr - Nuno

Reputation: 900

Try to instantiate resources that may not yet have loaded i not a good practice.

You should use an Controller Plugin instead.

Upvotes: 1

Related Questions