Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the fetch method in thinkphp

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to use the fetch method in thinkphp". In daily operation, I believe many people have doubts about how to use the fetch method in thinkphp. Xiaobian consulted all kinds of information and sorted out simple and easy to use operation methods. I hope to help you answer the doubts about "how to use the fetch method in thinkphp"! Next, please follow the small series to learn together!

In thinkphp, fetch method is used to render template file output. This method does not directly render output, but supports label parsing of template or content, and returns parsed content. The rendering output system will also automatically call send method to render output. The syntax is "$this->fetch(template name);".

Operating environment: Windows 10 system, ThinkPHP3.2 version, Dell G3 computer.

How to use fetch method in thinkphp

instantiate view class

5.0 Template rendering provides fetch and display methods, the most commonly used is fetch

fetch method is used to render template file output, while

The display method renders content output.

//instantiate view class $view = new \think\View(); //render template output return $view->fetch();

If your controller inherits the\think\Controller class, you can use the

//render template output return $this->fetch();

Note that ThinkPHP5's view fetch method doesn't render output directly, it just returns parsed content. If the controller class returns the view parse content, the render output system automatically calls the send method of the think\Response class to render the output.

template positioning rule

By default, the template file directory is located under the view directory of the module. The template file positioning rules in the fetch method of the view class are as follows:

If the fetch method is called without any arguments:

return $view->fetch();

Then locate the template file according to the default rules of the system to:

>[info] ### [template file directory]/current controller name (lowercase)/current operation name (lowercase).html

If (specify action) calls:

return $view->fetch('add');

The location template file is:

>[info] ### [template file directory]/current controller name/add.html

If one of the template files calling the controller uses:

return $view->fetch('user/add');

Then the location template file is:

The requested URL/user/add.html was not found on this server.

Full Path Template Call:

return $view->fetch(MODULE_PATH. 'view/public/header.html');

Then the location template file is:

MODULE_PATH. 'view/public/header.html'

At this point, the study of "how to use fetch method in thinkphp" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report