我想将一个页面(页面使用自己的模板)添加到另一个页面调用的视图中。
这行得通,我得到了数据,但是我得到了 index.php 上显示的 blog.php 的 3 个副本,我不明白为什么要这样做。
索引.php:
<?php
class page_index extends Page {
function init(){
parent::init();
$p=$this;
$p=$this->add('View',null,null,array('view/home'));
$p->template->tryset('pageblog',$this->add('page_blog'));
}
}
home.html(由 index.php 调用):
<div>
<?$pageblog?>
</div>
博客.php:
<?php
class page_blog extends Page {
function init(){
parent::init();
$page=$this;
//Get Articles
$articles=$this->add('Model_News')->getRows();
$page->add('H1')->set('Latest News');
foreach($articles as $article){
$content=$this->add('view',null,null,array('view/blog'));
$content->template->set('title',$article['title']);
$content->template->set('content',$article['content']);
}
}
}
blog.html(blog.php 的模板)
<div>
<h3><?$title?></h3>
<p><?$content?></p>
<hr>
</div>