-1
當我把這個地址example.com/js/config我需要加載一個配置文件的JS,但路由器加載控制器和顯示錯誤beacouse控制器dosn't存在。在bootstrap文件中,我放置了一個_init方法:Zend Framework如何禁用控制器
protected function _initJsConfig(){
$this->bootstrap('frontController');
$oFront = $this->getResource('frontController');
$oFront->setRequest(new Zend_Controller_Request_Http());
$oRequest = $oFront->getRequest();
$oRequest->setDispatched(false);
//$oFront = Zend_Controller_Front::getInstance()->getRequest();
if($oRequest->getControllerName() == 'js' && $oRequest->getActionName() == 'config'){
include('/config/config.js.php');
return;
}
}
但這不起作用。有任何想法嗎? 此致敬禮。
如果控制器不存在但請求仍然被路由到ZF,我猜測文件'js/config'在服務器上不存在,或者ZF的.htaccess規則沒有設置對。 – drew010
我知道我可以編輯.htaccess文件來禁用路由,但我想隱藏一個文件,所以沒有人能看到它的擴展名(.php)。所以當我把這個:我想開始:config.js.php文件。最好的祝福。 –
您擁有的代碼在引導程序中不起作用,因爲路由尚未建立並且沒有完成調度。您可以編寫一個[控制器插件](http://framework.zend.com/manual/1.12/en/zend.controller.plugins.html),其中包含與您擁有的代碼類似的代碼,因爲您可以截取它之前的控制器和操作實際上被分派(到不存在的控制器,然後處理錯誤)。 – drew010