Model view controller 使Zend查找我的自定义应用程序异常
我有一个类似于此线程的问题:[抛出-exceptions-from-model-view-controller-in-a-zend-framework-application][1] 我有这样的标准MVC结构:Model view controller 使Zend查找我的自定义应用程序异常,model-view-controller,zend-framework,exception,Model View Controller,Zend Framework,Exception,我有一个类似于此线程的问题:[抛出-exceptions-from-model-view-controller-in-a-zend-framework-application][1] 我有这样的标准MVC结构: /application /myapp /controllers /forms /models /exceptions Default.php (class Myapp_Exception_Default extends Zend_Exce
/application
/myapp
/controllers
/forms
/models
/exceptions
Default.php (class Myapp_Exception_Default extends Zend_Exception)
boostrap.php
无论我想做什么:
throw new Myapp_Exception_Default();
我得到:
Fatal error: Class 'Myapp_Exception_Default' not found
我的问题是如何让Zend找到我的自定义异常?我找不到任何配置选项来声明它。您应该有如下内容:
/application
/myapp
/controllers
/forms
/models
/exceptions
Default.php (class Myapp_Exception_Default extends Zend_Exception)
boostrap.php
关于这一内容:
...
protected function _initAutoload()
{
// Add autoloader empty namespace
$autoLoader = Zend_Loader_Autoloader::getInstance();
$autoLoader->suppressNotFoundWarnings(true);//http://zend-framework-community.634137.n4.nabble.com/Trouble-using-Gdata-Calendar-td675383.html
$autoLoader->registerNamespace('Gestionale_');
$resourceLoader = new Zend_Loader_Autoloader_Resource(
array(
'basePath' => APPLICATION_PATH,
'namespace' => '',
'resourceTypes' => array(
'form' =>
array(
'path' => 'forms/',
'namespace' => 'Form_',
),
'model' =>
array(
'path' => 'models/',
'namespace' => 'Model_'
),
),
));
// Return it so that it can be stored by the bootstrap
return $autoLoader;
}
使用此代码
<?php
/**
* Custom exception class that logs messages
*/
class Gestionale_Exceptions_Exception extends Exception
{
...
}
我知道这个解决方案,但我希望尽可能避免将Myapp的特定异常放入我的库文件夹,因为我经常在其他应用程序中重用库文件夹,所以我希望尽可能使它更通用。无论如何,我现在要使用这个解决方案,因为它是一个干净的解决方案,即使不是最合乎逻辑的,如果我提到自定义异常的目的。如果有人知道的更好,请分享:)感谢您快速详细的回答如果您添加类似“resourceTypes”=>array(“error”=>array(“path”=>“exceptions/”,“namespace”=>“MyApp”,)的内容会怎么样,可能会起作用。它不起作用。即使尝试在我的ini配置文件中声明它。你也可以在application.ini中声明
Myapp\uu
命名空间!