I started out with models in a module called Api, using the following
classname/filename conventions:
filename: {project}/application/modules/api/models/Account.php
classname: Api_Model_Account
They were happily autoloading through the framework as expected.
I decided that some of these models would be better off,
organisationally speaking, in the application’s models directory as they
could be used across multiple modules.
I moved them and renamed them:
filename: {project}/application/models/Account.php
classname: Application_Model_Account
However, they are not autoloading – PHP throws a class not found. I have checked and confirmed my
configuration ({project}/application/configs/application.ini):
[production]
appnamespace = "Application"
So, the application namespace is ‘Application’, but the models in the
application/models directory are not being autoloaded.
Just to make things that little bit crazier – the plugins in application/plugins are being autoloaded.
Testing:
<?php
class Application_Model_ExampleTest extends AMH_Test_PHPUnit_ControllerTestCase
{
public function testLoad()
{
$moduleModel = new Api_Model_Product();
$plugin = new Application_Plugin_ModuleErrorControllerSelector();
$applicationModel = new Application_Model_Example();
}
}
class AMH_Test_PHPUnit_ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
public function setUp()
{
$this->bootstrap = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
parent::setUp();
}
public function tearDown()
{
$this->resetRequest();
$this->resetResponse();
parent::tearDown();
}
}
Configuration:
[production]
appnamespace = "Application"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
includePaths.library = APPLICATION_PATH "/../library"
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
phpSettings.date.timezone = "Australia/Adelaide"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.displayExceptions = 0
resources.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
Relevant folder paths:
<project name>/
application/
models/
Example.php
modules/
api/
models/
Product.php
plugins/
ModuleErrorControllerSelector.php
Error message:
PHP Fatal error: Class 'Application_Model_Example' not found in /var/www/accounts.amh.localhost/tests/application/models/ExampleTest.php on line 9
This is using Zend Framework 1.10 (package for Ubuntu 10.04)
This method needs to be in all tests to ensure the environment is properly bootstrapped: