模板赋值函数,可以直接赋值变量,数组或者对象。在Controller中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $key | String | 是 | KEY值-模板中的变量名称 |
| $value | String | 否 | 模板变量值 |
class indexController extends Controller {
public $initphp_list = array('test');
public function run() {
$username = 'initphp';
$this->view->assign('username', $username); //模板赋值
$this->view->set_tpl('header'); //设置模板
$this->view->set_tpl('test/test'); //设置模板
$this->view->remove_tpl('header'); //移除模板
$this->view->display(); //模板显示
}
public function test() {
echo 'Hello World';
}
/**
* @return testService
*/
private function getTestService() {
return InitPHP::getService('test','test');
}
}
模板-显示视图。在Controller中需要显示模板,就必须调用该函数。模板解析可以设置 $InitPHP_conf['isviewfilter'] 值,对变量进行过滤。在Controller中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $template | String | 否 | 可以直接添加模板并且输出,例如$this->view->display('user_add') |
public function run() {
$username = 'initphp';
$this->view->assign('username', $username); //模板赋值
$this->view->set_tpl('header'); //设置模板
$this->view->set_tpl('test/test'); //设置模板
$this->view->remove_tpl('header'); //移除模板
$this->view->display(); //模板显示
}
可以直接获取到您已经设置的模板信息,数组形式返回。在Controller中使用
public function run() {
$username = 'initphp';
$this->view->assign('username', $username); //模板赋值
$this->view->set_tpl('header'); //设置模板
$this->view->set_tpl('test/test'); //设置模板
$this->view->remove_tpl('header'); //移除模板
print_r($this->view->get_tpl()); //打印模板
$this->view->display(); //模板显示
}
如果在控制器的基类中已经导入头部和脚步模板,应用中需要替换头部模板。移除模板需要在display() 模板显示前使用。在Controller中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $template_name | String | 是 | 模板名称,不需要带.htm后缀,如果有文件夹,例如:test/test 或者 header |
public function run() {
$username = 'initphp';
$this->view->assign('username', $username); //模板赋值
$this->view->set_tpl('header'); //设置模板
$this->view->set_tpl('test/test'); //设置模板
$this->view->remove_tpl('header'); //移除模板
$this->view->display(); //模板显示
}
设置模板名称,不需要带.htm后缀,如果有文件夹,例如:test/test 或者 header。$type提供了头部和脚步模板的功能,如果为F,则模板输出顺序为最先,L为最后,为空则默认。在Controller中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $template_name | String | 是 | 模板名称,不需要带.htm后缀,如果有文件夹,例如:test/test 或者 header |
| $type | String | 否 | $type提供了头部和脚步模板的功能,如果为F,则模板输出顺序为最先,L为最后,为空则默认 |
public function run() {
$username = 'initphp';
$this->view->assign('username', $username); //模板赋值
$this->view->set_tpl('header'); //设置模板
$this->view->set_tpl('test/test'); //设置模板
$this->view->remove_tpl('header'); //移除模板
$this->view->display(); //模板显示
}