Home > Hosting > System

Difference: view and fetch methods in TP5 controller

2024-02-18 12:00:26

The following column of thinkphp framework tutorial introduces the difference between view and fetch in TP5 controller, hoping to help friends in need!

Difference between view and fetch in TP5 Controller

In the controller, the similarities and differences between the two methods.

In the controller, the three rendering methods of templates have different configuration and display.

//Do not inherit the controller. $view = new view(); return $view->fetch('index/demo');

//Do not inherit the controller. return view('index/demo');

//inherit the controller return $this->fetch('index/demo');

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

In the project, try to use the latter two.

Writing, or inherit the controller,this->fetch.

Or use the view method

new view();

But this kind of unreadable public configuration file needs to set its own parameters, instantiate the object, and pass the parameters in, such as writing.


Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us