0

In the view and layout scripts of my MVC application I regularly require access to convenience methods such as isLoggedIn() or isAdmin(). I would like to put these in a base view so that I can access them with $this->isLoggedIn() or $this->isAdmin(). What's the right way to do this?

I tried extending Zend_View with MY_Base_View. I then created a View resource and initialised it from my bootstrap. I know that its being initialised because the page title works fine. Here's the code from the resource:

$this->_view = new MY_Base_View();
$this->_view->headTitle('My page title!');

When I'm in the view script, however, if I print_r($this), it says the object is a Zend View object, (not MY_Base_View).

Have had similar problems with the layout to.

Thanks!

4

1 に答える 1

0

ああ!! 整理した。ビュー リソースでは、ViewRenderer のビューを次のように設定する必要がありました。

    $viewRenderer = Zend_Controller_Action_HelperBroker
        ::getStaticHelper('ViewRenderer');
    $viewRenderer->setView($this->_view);           

(マニュアルの「リソース」セクションにあります!) とにかく、私がしなければならなかったのはそれだけです。その作業を行うために、レイアウトはレンダラーに登録されたビューを探します...

于 2013-03-22T07:15:45.820 に答える