2010-06-15 25 views
1

我試圖設置一個視圖腳本除了當前請求的操作視圖腳本被執行。我想以控制器操作本身的方式執行此操作,以便可以從佈局$ this-> layout() - > content helper獲取此新的視圖腳本輸出。設置/添加視圖從控制器動作

我找到了setView()方法,但不知道如何從控制器使用它。

非常感謝。

+0

你想輸出第二個腳本INSEATD的另一個或concatinate他們? – Ololo 2010-06-15 11:59:27

+0

如果有人能告訴我2種方法(替換或連接),那麼這將是perfet。 – Max 2010-06-15 12:58:15

回答

6

如果你只是想從一個控制器只呈現一些其他的視圖腳本:

$this->render('someotherview'); 

至極將呈現someotherview.phtml。 來自:http://framework.zend.com/manual/en/zend.controller.action.html#zend.controller.action.viewintegration.render

class MyController extends Zend_Controller_Action{ 
public function fooAction() 
{ 
    // Renders my/foo.phtml 
    $this->render(); 

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

    // Renders baz.phtml 
    $this->render('baz', null, true); 

    // Renders my/login.phtml to the 'form' segment of the 
    // response object 
    $this->render('login', 'form'); 

    // Renders site.phtml to the 'page' segment of the response 
    // object; does not use the 'my/' subirectory 
    $this->render('site', 'page', true); 
} 

public function bazBatAction() 
{ 
    // Renders my/baz-bat.phtml 
    $this->render(); 
} 

}

應該讓你在正確的軌道上!

而且

$this->renderScript('path/to/index.phtml'); 

的作品真的很好。

+0

非常感謝。如果它不起作用,將更新問題。 – Max 2010-06-19 20:34:19