2009年3月30日星期一

Re: [fw-mvc] Accessing view placeholders in view helper called in layout

Try add to your helper:
public $view;
and
public function setView(Zend_View_Interface $view)
{
$this->view = $view;
}


2009/3/30 Václav Vaník <vanik@walk.cz>:
>
> Hi guys,
>
> I have problem with appending e.g. CSS files in view helper called in
> layout.phtml
>
> My example:
>
> bootstrap:
>
>    $view = new Zend_View(array('encoding' => 'UTF-8'));
>    $view->addHelperPath(ROOT_DIR . '/app/www/views/helpers',
> 'Walk_View_Helper');
>    $view->addScriptPath(ROOT_DIR . '/app/www/views/scripts');
>    $view->doctype('XHTML1_STRICT');
>
>    $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
>    Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
>
>    $layout = Zend_Layout::startMvc(/path/to/layout.phtml);
>    $layout->setView($view);
>
> layout.phtml:
>
> <?php echo $this->doctype('XHTML1_STRICT'); ?>
> <htm>
> <head>
> <?php echo $this->headLink(); ?>
> </head>
> <body>
>
> <?php echo $this->myHelper(); ?>
>
> </body>
> </html>
>
> MyHelper:
>
> class Walk_MyHelper extends Zend_View_Helper_Abstract
> {
> public function myHelper()
> {
> $this->view->headLink()->appendStylesheet('/path/to/css');
> return 'foo';
> }
> }
>
> It seems helper "doesn't see" $this->view :(
> --
> View this message in context: http://www.nabble.com/Accessing-view-placeholders-in-view-helper-called-in-layout-tp22782923p22782923.html
> Sent from the Zend MVC mailing list archive at Nabble.com.
>
>

--
Paweł Chuchmała
pawel.chuchmala at gmail dot com

没有评论: