Home > PHP Framework > ThinkPHP > body text

Difference: view and fetch methods in TP5 controller

藏色散人
Release: 2020-09-03 14:02:12
forward
3918 people have browsed it

The following is the thinkphp framework tutorial column to introduce to you the differences between the view and fetch methods in the TP5 controller. I hope it will be helpful to friends in need!

Difference: view and fetch methods in TP5 controller

TP5 The difference between the view and fetch methods in the controller

In the controller, the two methods are similar and different

In the controller, the three rendering methods of the template have different configuration displays.

//不继承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

The latter two can output public configuration, tpl_replace_string, such as __CSS__, the path can be output in the template, the first type, the __CSS__ string can be output directly in the template

In the project, Try to use the latter two

writing methods, or inherit controller, this->fetch

or use the view method

new view();
Copy after login

but this cannot be read For the public configuration file, you need to set the parameters yourself. After instantiating the object, pass the parameters in, for example, write

Difference: view and fetch methods in TP5 controller

The above is the detailed content of Difference: view and fetch methods in TP5 controller. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!