ang*_*ezi 2 cakephp view extend
我有一个包含的子视图文件
<!-- src/Template/Posts/view.ctp -->
<?php
$this->extend('/Common/view');
//1
$this->assign('title', $post);
//2
$this->start('sidebar');
//...
$this->end();
?>
Run Code Online (Sandbox Code Playgroud)
及其包含的父级
<!-- src/Template/Common/view.ctp -->
<h1><?= $this->fetch('title') ?></h1>
<?= $this->fetch('sidebar') ?>
Run Code Online (Sandbox Code Playgroud)
我可以通过方法1,2传递字符串.但是如何将变量从子视图传递给其父视图?
感谢所有试图告诉"这是不可能的"的人在您的子视图中设置变量
$this->set('toParent' , $toParent);
Run Code Online (Sandbox Code Playgroud)
并且很容易在父视图中使用它
$toParent = $this->get('toParent');
Run Code Online (Sandbox Code Playgroud)
你可以看到这是可能的:)