Zend Framework - 对控制器中的不同操作使用通用标头?

发布于 2024-10-19 01:44:32 字数 1754 浏览 3 评论 0原文

我尝试阅读此处找到的问题: 模块配置和布局配置zend 框架 它被描述为我需要了解的有关布局的一切 - 但是 - 恐怕我发现它有点难以理解。

我有许多 Zend 控制器:

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
}

我需要它们具有以下排列。

  1. 第一控制器和第二个控制器共享一个标头
  2. FirstController - indexAction 和 browserAction 共享一个附加标头
  3. Thirdcontroller - 有它自己的标头或可能“没有标头”(对于 ajax)

就目前情况而言,我在 view/script/< 中得到了巨大的复制;actionname>.phtml 文件 http://framework. zend.com/manual/en/zend.layout.quickstart.html

有更多信息,但我无法找到让我明白这一切的关键信息。

从上面的第一个文档中,我猜测以下内容会进入我的 application.ini 文件,

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

但是我是否期望创建一个名为“Layouts”的文件夹,或者我应该使用某种 views/通用文件夹?该文件是否名为 layout.php

那么,在 layout.php 中,我是否正确理解

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

Will 渲染单个操作的 PHTML 文件?并使

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

整个操作使用不同的布局文件(布局文件夹中名为“foobaz.php”的文件)?

感谢您花时间为我解决这个问题。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东风软 2024-10-26 01:44:32

是的,你说得对,

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

应该用不同的布局渲染页面,并简单地在layout()->content占位符中输出视图内容。

另一种方法是使用单一布局,并使用部分加载不同的标题。

在你的行动中你可以有

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

然后在你的布局中你可以这样做

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

这可能是在顶部。

Yea, you have it right,

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

Should render the page with a different layout, and simply output the views contents in the layout()->content place holder.

Another way would be to have a single layout, and use partials to load different headers.

In your action you could have

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

Then in your layout you could just do this

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

This is probably over the top.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文