所以我有一个关于 Zend 框架在布局方面的一般代码组织的问题。
我的布局基本上是这样的:
(LAYOUT.PHTML)
<div id='header'>
<?= $this->Layout()->header ?>
</div>
<div id='main'>
<?= $this->Layout()->main ?>
</div>
<div id='footer'>
<?= $this->Layout()->footer ?>
</div>
等等等等。现在,为了使页眉中的代码与主代码和页脚代码分开,我为视图创建了一个文件夹,其中包含 header.phtml、main.phtml、footer.phtml。然后我使用此代码将 header.phtml 的内容分配给 $this->layout()->header:
(INDEX.PHTML)
$this->Layout()->header = file_get_contents('index/header.phtml');
$this->Layout()->main = file_get_contents('index/main.phtml');
$this->Layout()->footer = file_get_contents('index/footer.phtml');
那工作得很好,但我已经到了不想让 main 成为静态 HTML 的地步。我希望能够用 PHP 插入一些值。因此,在 indexAction 的控制器中,我希望能够从我的数据库中加载并将值放入 index/main.phtml。有没有办法在不重组我的网站的情况下做到这一点?
如果没有,有没有办法做到这一点,以便我可以拥有:
将代码放入布局的不同部分的能力,例如 Layout()->header、Layout->footer。
将这些部分分成不同的文件,以便于查找和组织它们,例如我的 index/footer.phtml、index/main.phtml 等。
不必将该代码不必要地放入引号中以将其转换为字符串以将其传递给 Layout()->header 等。
非常感谢你们的帮助。
-伊森