下面以header和footer为例:
1、建立IncludeController
namespace Admin\Controller;
use Think\Controller;
class IncludeController extends Controller {
public function header(){
//测试动态数据
$Test = M('system_user');
$data = $Test->select();
$this->assign('data',$data);
//大招:这里必须用T方法
$this->display(T('Admin@Include:header'));
}
public function footer(){
//大招:这里必须用T方法
$this->display(T('Admin@Include:footer'));
}
}2、建立header和footer模板文件<!-- header.html -->
<h1>Include Header</h1>
<?php dump($data); //测试动态数据 ?><!-- footer.html -->
<h1>Include Footer</h1>3、在任意模块的模板中调用header和footer(比如要在Home模块的模板中调用Admin模块中的header和footer)<!-- index.html -->
<?php $Include = A('Admin/Include'); //大招:使用A方法 ?>
<?php $Include->header(); ?>
<h1>Index Content</h1>
<?php $Include->footer(); ?>哟嚯嚯嚯!是不是很简单很方便?代码管理起来也轻松多了~ 最佳答案