use*_*120 8 php zend-framework autoload zend-autoloader
我在这里定义了一个类库.../projectname/library/Me/Myclass.php定义如下:
<?php
class Me_Myclass{
}
?>
Run Code Online (Sandbox Code Playgroud)
我有以下引导程序:
<?php
/**
* Application bootstrap
*
* @uses Zend_Application_Bootstrap_Bootstrap
*/
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
/**
* Bootstrap autoloader for application resources
*
* @return Zend_Application_Module_Autoloader
*/
protected function _initAutoload()
{
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Default',
'basePath' => dirname(__FILE__),
));
$autoloader->registerNamespace('Me_');
return $autoloader;
}
/**
* Bootstrap the view doctype
*
* @return void
*/
protected function _initDoctype()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('XHTML1_STRICT');
}
/**
* Bootstrap registry and store configuration information
*
* @return void
*/
protected function _initRegistry()
{
$config = new Zend_Config_Ini(APPLICATION_PATH .
'/configs/application.ini', APPLICATION_ENV,
array('allowModifications'=>true));
Zend_Registry::set('configuration', $config);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我尝试像这样实例化类:
<?php
class SomeController extends Zend_Controller_Action
{
public function indexAction()
{
$classMaker=new Me_Myclass();
}
}
?>
Run Code Online (Sandbox Code Playgroud)
当我直接导航到http:/something.com/projectname/some?id = 1时,我收到以下错误:
致命错误:在第x行的/home/myuser/work/projectname/application/controllers/SomeController.php中找不到类'Me_Myclass'
有任何想法吗?
潜在的相关杂记:
当我使用我在应用程序/库下的其他文件夹中定义的类扩展模型时,自动加载器似乎有效.
有人建议更改我尝试的"默认",但它似乎没有解决问题,并且使用此命名空间破坏了模型功能的额外负面影响.
sma*_*007 13
你的类需要名为Me_Myclass:
class Me_Myclass
{
}
Run Code Online (Sandbox Code Playgroud)
将库文件夹向上移动一级,以便具有文件夹结构:
/
/application
/library
/public
Run Code Online (Sandbox Code Playgroud)
然后在你的Bootstrap中将以下内容添加到_initAutoload():
Zend_Loader_Autoloader::getInstance()->registerNamespace('Me_');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17490 次 |
| 最近记录: |