|
PHP复制代码
function index ()
{
$limit=5;
//$content = $this->viewlist($limit);
$pagetitle = "HOME";//$this->viewlist->pagetitle ;
$themes = "fresh";
$c;
$this->layout($pagetitle,$themes,$limit,$content);
}
function layout ($pagetitle,$themes,$limit,$content)
{
$post_list = new View ("themes/".$themes."/layout");
$post_list->head = new View ("themes/".$themes."/head");
$post_list->head->title = $pagetitle;
$post_list->head->render(TRUE);
$post_list->header = new View ("themes/".$themes."/header");
$post_list->header->render(TRUE);
$post_list->siderbar = "sidebar for test";
//$post_list->siderbar->render(TRUE);
$post_list->content = new View ("themes/".$themes."/".$content);
$this->viewlist($limit,$themes);
$post_list->content->render(TRUE);
$this->viewlist($limit,$themes);
$post_list->footer = new View ("themes/".$themes."/footer");
$post_list->footer->render(TRUE);
}
function viewlist ($limit,$themes)
{
$post=new Post_Model ;
$list = $post->find_all();
$post_list= new View ("themes/".$themes."/list");
//$pagetitle= __FUNCTION__;
//$post_list = new View("themes/".$themes."/layout");
foreach ($list as $lists):
$id = $lists->id ;
$title = $lists->title ;
$date = $lists->date ;
$post_list->date = $date;
$post_list->link = html ::anchor( [url =:site ($id]url ::site($id[/url ], 'http'),$title);
//$post_list->content = new View("themes/".$themes."/list");
//$post_list->content->render(TRUE);
endforeach;
}
复制代码
以上是controllers中的;
—————————————————————
views中的list是这样的;
<div id='post_list'>
<h2><?php echo $link ?></h2>
<h3><?php echo $date;?></h3>
</div>
————————————————————
问题是:如何可以设计一个$content,能够让layout()接受$content之后,能正常显示。
PHP新手,请见谅。
是不是用case可以解决?
或者是另外的设计思路。
————————————————————
我的目的是写一个MVC完全分离的页面生成。之间用了ORM。
____________________________________
其实就是简单的用ORM提取数据,
然后用controllers传递给相应的View展示出来。
layout可以不用这样写。
可是我想用同一个layout展示不一样的内容,这样比较方便。
[ 本帖最后由 e6nian 于 2008-2-15 15:52 编辑 ] |
|