以上两种常见的目录结构。
第一种,我们可以在index.php中如此设置:$front=Zend_Controller_Front::getInstance();
$front->setControllerDirectory('../application/default/controllers');
$front->addControllerDirectory('../application/modules/product/controllers','product');
或者:$front->setControllerDirectory(array('default'=>'../application/default/controllers'
,'product'=>'../application/modules/product/controllers));
第二种目录结构:$front->addModuleDirectory('../application/modules');
注意:
在product目录下的controller名字前要加Product_,比如product/controllers/IndexController.php里的class必需用Product_IndexController,此时用http://localhost/mymodule就可以顺利的登入到自己定义的module里了.
…………………………………………………………………………………………………………………………………………………………………………………………………………
关于controllers,models,views文件夹。controllers中的动作会自动映射view中的脚本。若要在controllers中调用models文件夹下的文件中的类,需要在index.php中设置set_include_path();如上例中,须这样设置:set_include_path('.' . PATH_SEPARATOR . '../library' . PATH_SEPARATOR . '../application/modules/default/models' . PATH_SEPARATOR . '../application/modules/product/models' . PATH_SEPARATOR . get_include_path());所用到的models文件夹都应包含在内。
设置好以后,可以在controllers中调用时添加Zend_Loader::loadClass('类名');也可以直接在index.php中加入如下函数:
function __autoload($class)
{
require_once("{$class}.php");
}
这样,controllers中可以直接用所需要的类,而不必用Zend_Loader::loadClass(' 类名');加载。
注意:
models中的类名必须与定义类的文件名相同 才能正确加载。例如,news.php中定义的类名必须为class news{}
以上两种常见的目录结构。
第一种,我们可以在index.php中如此设置:$front=Zend_Controller_Front::getInstance();
$front->setControllerDirectory('../application/default/controllers');
$front->addControllerDirectory('../application/modules/product/controllers','product');
或者:$front->setControllerDirectory(array('default'=>'../application/default/controllers'
,'product'=>'../application/modules/product/controllers));