0

I have stuck with implementing a simple scenario. I have 2 views for a single controller

MyController 
  view/scripts/my/index.phtml
                 /index2.phtml

I know $this->view->test = "test" will set 'test' view variable for index.phtml. but I would like to know how to set a variable for index2.phtml.

4

1 回答 1

1

在你的控制器中设置$this->view->test = "test"将设置视图变量,这些变量可以被之后通过调用渲染的任何模板使用:

$this->render('your action');

例如:

class MyController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $this->view->test = "test"

        // Renders my/index.phtml
        $this->render();

        // Renders my/index2.phtml
        $this->render('index2');    
    }
}

在这两个模板中,您都可以访问该test属性。

于 2013-04-23T21:56:20.523 回答