php - 如何在 $this->fetch() cakephp 2.1 上指定值

标签 php cakephp view controller

我们都知道 $content_for_layout 现在在 cakephp 2.1 中已被弃用并更改为 $this->fetch('content');

无论我们将 fetch('content') 放在哪里,都将在其中查看布局标记的 View 内容。

我的问题是,例如我有一个 View navigation(),该 View 的内容将放置在 $this->fetch('nav_view') 上,而对于 View main_board() ,内容将放置在 $this 上->fetch('main_board'),

这两个提取将在同一布局上输出。这可能吗?

最佳答案

在你的 View /元素/助手中的某个地方:

$this->start('nav_view');
// render your 'nav_view' stuff here
echo $this->element('...');
$this->end();

渲染与内容相同:

// in layout
$this->fetch('nav_view');

显然,这现在已记录在食谱中的 Using view blocks 下.

关于php - 如何在 $this->fetch() cakephp 2.1 上指定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10891864/

相关文章:

javascript - Javascript/PHP/Codeigniter 中的悬停事件

php - 如何将 PHP 变量传递给 angular js?

mysql - CakePHP 3 表关系

javascript - 使用 CSS 和 imgs 将 Javascript 库导入 CakePHP

ios - 使用实例方法以编程方式添加 subview

php - 检查纬度/经度位置位于多边形内

javascript - php 如何检查字符串中某个单词是否重复

mysql - CakePHP 排序顺序不影响所有记录

Django 和通用 View

c# - 更新 Controller 中的模型?