开发者

FrontController in ZendFramework 1.11.3

What is purpose of thi开发者_Go百科s method in Bootstrap.php?

protected function _initFrontControler(){
    $this->bootstrap('FrontController');
    $frontController = Zend_Controller_Front::getInstance();

    $frontController->throwExceptions(true);
    $frontController->returnResponse(true); 

    try { 
        $response = $frontController->dispatch();
        if($response->isException()) { 
            throw new Exception; 
        } 
        $response->sendResponse();
    } catch (Exception $e) { 
        print $e->getMessage(); 
    }
}

I know that it can handle errors but then layouts for example doesn't work. What is complete implementation of this method to behave identically like default (or without this method).


You bootstrap layout too, maybe in separate resource initialization function, e.g.:

protected function _initViewSetting(){
 $this->bootstrap('layout');
 $this->bootstrap('view');

 ...
}

Or you can do that in config file (ini/xml) and resource will load automatically. Actually, if you look deeper into ZF code, you'll see that FrontController is already loaded automatically.So instead of $this->bootstrap('FrontController'), you could use $this->getResource('FronController')

Personally, I wouldn't use the code you supplied. It just uses FrontController and dispatches the request, and takes care of exception handling. If that is in bootstrap, calling dispatch() directly is not very wise to do. Someone correct me if I'm wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜