Difference: view and fetch methods in TP5 controller
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!
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');
//不继承controller return view('index/demo');
//继承controller return $this->fetch('index/demo');
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();
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
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Recently, during the development of Vue applications, I encountered a common problem: "TypeError: Failedtofetch" error message. This problem occurs when using axios to make HTTP requests and the backend server does not respond to the request correctly. This error message usually indicates that the request cannot reach the server, possibly due to network reasons or the server not responding. What should we do after this error message appears? Here are some workarounds: Check your network connection due to

Laravel is one of the most popular PHP frameworks currently, and its powerful view generation capabilities are impressive. A view is a page or visual element displayed to the user in a web application, which contains code such as HTML, CSS, and JavaScript. LaravelView allows developers to use a structured template language to build web pages and generate corresponding views through controllers and routing. In this article, we will explore how to generate views using LaravelView. 1. What

In Vue project development, data request and processing are very important links. A good data request and processing strategy can greatly improve application performance and user experience. This article will share some experiences in data request and processing in Vue project development. Proper use of the Axios library Axios is a commonly used Promise-based HTTP library for sending XHR requests. In a Vue project, you can use Axios to send data requests. When using Axios, you need to pay attention to the following points: Properly configure A

The method for PHP to use tp5 to query the total number of data is: 1. Create a PHP sample file; 2. Create the variable $count and introduce the Db class; 3. Use the "count()" method to query the total number of data in the table named user. And store the result in the variable $count; 4. Output the total number through the echo statement.

First of all, the fetch method is a rendering method in the ThinkPHP framework. This method is mainly used to load the view page and render it. This method is defined in the View class of the ThinkPHP framework, therefore, we need to find the View class first. The path of the View class in the ThinkPHP framework is as follows: thinkphp/library/think/View.php. We can find the source code file where the View class is located through this path. Open the View.php source file, we can see that the fetch() method is defined in the View class, its code is as follows: /***Rendering template output*@acces

Usage of fetch method in JavaScript In modern web development, data interaction with the server is a very common requirement. To meet this need, JavaScript provides the fetch method, which is a powerful and easy-to-use API that can help us send and receive HTTP requests. The basic usage of the fetch method is as follows: fetch(url,options).then(response=>res

Use reflection combined with dynamic proxy to implement a View annotation binding library that supports View and event binding. The code is concise, easy to use, and has strong scalability. Supported functions @ContentView binds layout instead of setContentView() @BindView binds View instead of findViewById() @OnClick binds click event instead of setOnClickListener() @OnLongClick binds long press event instead of setOnLongClickListener() Code annotation class @Target(ElementType. TYPE)@Retention(Rete

Methods for react fetch to request data: 1. Place the requested method in the "componentDidMount" of the life cycle; 2. Encapsulate the fetch request; 3. Check the request status through the "function checkStatus(response){...}" method; 4. , just use the encapsulated request and print the result on the server or browser.
