开发者

Autoload models with zend in bootstrap.php

I really can't figure this out:

I've created a file called User.php in application/models. The classname in it is Model_User.

When I try to create an object in my Controller, I get this error:

Fatal error: Class 'Model_User' not found in C:\xampplite\htdocs\code\application\controllers\IndexController.php on line 14

I googled around, and found this code, which is supposed to autoload controllers for me, it is located in bootstrap.php The code isn't working though. The example that used this code was working with ZF 1.8 so that might be the reason but I can't figure it out. How should I autoload my models?!

    private function _initAutoload(){
 $modelLoader = new Zend_Application_Module_Autoloader(array(
     'namespace' => '',
     'basePath' =开发者_Go百科> APPLICATION_PATH
 ));
 return $modelLoader;
    }

Any ideas?


The important bit in the answer to the question I linked above is the namespace:

    $resourceLoader->addResourceTypes(array(
            'model' => array(
                    'namespace' => 'Model',
                    'path'      => 'models'
            )
    ));

The namespace parameter tells the Autoloader to look in the defined path (relative to basePath) when encountering a class that starts with Model_. You have the first part right, but you're missing the call to addResourceTypes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜