Sunday, April 8, 2012

Fatal error: Class 'Model_XXXX' not found in Zend Framework

You're here because you have the same problem as I had and you kept on seeing that error several times. The problem here is not really a problem but rather you have a namespace set for your application inherited by how your models are being loaded. If you used the ZFTool it is more than likely that the namespace is the default which is "Application". In order for the usual or earliest form of ZF model initialization to work, you need to eliminate the namespace.

How do I eliminate the Zend Framework Application (or  Model Namespace)?

There are several ways to do it.

1. Configuration (application.ini)

appnamespace = ""

2. Bootstrap class by calling the module autoloader class

$moduleLoader = new Zend_Application_Module_Autoloader(array(
                                                                    'namespace' => '',
                                                                    'basePath' => APPLICATION_PATH)

3. Bootstrap class by calling the resource autoloader class

  $resourceLoader = new Zend_Loader_Autoloader_Resource(array(
                'basePath'  =>  APPLICATION_PATH,
                'namespace' => ''

                'model' => array(
                        'namespace' => 'Model',
                        'path'      => 'models'

#3 is from here.

There's a call hierarchy from the choices above which is easy to figure once you're using it. Depending on your use-case, you might need one or a combination of them. I hope this helps.
  • Related Links Widget for Blogspot

No comments: