(只需添加一个答案,以便这个问题显示为已回答,即使它已在评论中得到有效回答)
正如其他人在评论中提到的那样,您只能从控制器渲染一个视图。你会想要使用元素。元素是可重用的视图片段。
如果您有一个名为 的视图文件my_view.ctp,则可以向其中添加以下代码,以包含两个元素,称为“hello_world”和“name_details”:
$this->element('hello_world'); // <= element with no parameters
// example passing parameters to the element
$this->element('name_details', array('first' => 'John', 'last' => 'smith'));
您的元素文件将进入app/views/elements并被调用hello_world.ctp,并且name_details.ctp. 您传入的参数将作为变量使用,因此name_details.ctp可能如下所示:
First Name: <?php echo $first; ?>
<br />
Last Name: <?php echo $last; ?>
另请注意,在控制器中设置的视图变量将自动在元素中可用。