1

I've tried reading the question found HERE: Module configuration and layout configuration in zend framework It was described as being everything I need to know about layouts - but - I'm afraid I'm finding it a bit difficult to understand.

I've got a number of Zend controllers:

class FirstController extends Zend_Controller_Action {
   public function init()        { /* stuff */ } 
   public function indexAction() { /* stuff */ } 
   public function indexBrowse() { /* stuff */ } 
}

class SecondController extends Zend_Controller_Action {
    // stuff   
}

class ThirdController extends Zend_Controller_Action {
    // stuff
}

I need them to have the following arrangement.

  1. FirstController & Second Controller share a header
  2. FirstController - indexAction and browseAction share an additional header
  3. Thirdcontroller - has it's own header or possibly "no header" (for ajax)

As it stands, I'm getting tremendous replication in the view/script/<actionname>.phtml file http://framework.zend.com/manual/en/zend.layout.quickstart.html

Has more information but I've not been able to find the key pieces of information that bring this all home for me.

From the first document above I'm guessing the following goes into my application.ini file

 resources.layout.layout = "layout"
 resources.layout.layoutPath = APPLICATION_PATH "/layouts"

But am I expected to create a folder called "Layouts" or should I be using some sort of views/common folder? Is the file then called layout.php ?

Then, inside the layout.php am I understanding correctly that

    <div id="content"><?php echo $this->layout()->content ?></div>

Will render the individual action's PHTML file? and

   public function anotherAction() {
        $this->_helper->layout->setLayout('foobaz');
   }

Would make the entire action use a different layout file (one in the layouts folder called 'foobaz.php')?

Thanks for taking the time to clear this up for me.

4

1 に答える 1

2

ええ、あなたはそれを正しく持っています。

 $this->_helper->layout->setLayout('foobaz');

別のレイアウトでページをレンダリングし、ビューのコンテンツを layout()->content プレースホルダーに出力するだけです。

もう 1 つの方法は、単一のレイアウトを持ち、パーシャルを使用してさまざまなヘッダーをロードすることです。

あなたの行動であなたが持つことができる

 public function indexAction() { 
       $layout = $this->_helper->layout();
       $layout->assign('header', 'header_file_name');
}

次に、レイアウトでこれを行うことができます

   <div id="header">
       <?php echo $this->partial($this->layout()->header);?>
 </div>

これはおそらくオーバーです。

于 2011-02-21T21:37:15.797 に答える