0

コピー/貼り付けを避けるために、さまざまなアクションに固有のビューを使用できます。これらの方法のいずれかを使用してこれを行うことができます

$this->renderScript('index/index.phtml'); 
$this->view->var = "hello world";   

また

$this->_helper->viewRenderer('index');
$this->view->var = "hello world";

別のコントローラーを使用する場合は、最初のコントローラーを使用する必要があります。viewRenderer は問題ありませんが、renderScript を使用すると、未定義のようなものは何も表示varされません。ビュー スクリプトに値を割り当てるにはどうすればよいですか?

index.phtml は次のようになります

echo $this->var ;

4

1 に答える 1

2

それはあなたがそれを説明したように動作するはずです

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
        $this->view->var = 'echo me in any action viewscript and i will show you text';
    }

    public function indexAction()
    {
        // action body
        $this->view->test = 'Don\'t put me here becuase this is not the action that is run';

    }

    public function testAction()
    {
        // action body

        $this->view->test = 'Hello world';
        $this->renderScript('index/index.phtml');
        // or $this->_helper->viewRenderer('index');
    }

}

私の見解では(index.phtml)

私は持っています

<?php echo $this->test;?> 

/ index / test /に移動すると、「helloworld」と表示されます...

また、別のコントローラーで実行すると、結果が得られます

class MyController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
        $this->view->test = 'Hello world';
        $this->renderScript('index/index.phtml'); 
    }

}
于 2012-06-18T09:09:37.777 に答える