Home > Backend Development > PHP Tutorial > TP控制器中view和fetch的区别是什么?

TP控制器中view和fetch的区别是什么?

PHPz
Release: 2020-09-05 09:52:07
Original
1999 people have browsed it

TP控制器中view和fetch的区别是什么?

TP控制器中view和fetch两种方法的区别

在controller里面,两种方法异同

控制器中,模板三种渲染方法,配置显示不一样。

//不继承controller
$view = new view();
return $view->fetch('index/demo');
Copy after login
//不继承controller
return view('index/demo');
Copy after login
//继承controller
return $this->fetch('index/demo');
Copy after login

后两种能输出公共配置的,tpl_replace_string,比如__CSS__,模板里能输出路径,第一种,模板里直接输出__CSS__字符串

项目中,尽量用 后两种

写法,或者继承controller,this->fetch

或者用view方法

new view();
Copy after login

但是这种不能读公共配置文件,需要自己设置参数,实例化对象之后,传参进去,比如这么写

1.png

更多相关知识,请访问 PHP中文网!!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template