Home PHP Framework ThinkPHP Difference: view and fetch methods in TP5 controller

Difference: view and fetch methods in TP5 controller

Sep 03, 2020 pm 02:00 PM
fetch tp5 view

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if 'TypeError: Failed to fetch' occurs when using axios in a Vue application? What should I do if 'TypeError: Failed to fetch' occurs when using axios in a Vue application? Jun 24, 2023 pm 11:03 PM

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 development: How to generate views using Laravel View? Laravel development: How to generate views using Laravel View? Jun 14, 2023 pm 03:28 PM

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

Data request and processing experience in Vue project development Data request and processing experience in Vue project development Nov 02, 2023 am 10:35 AM

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

How to use tp5 to query the total number of data in php How to use tp5 to query the total number of data in php Jun 06, 2023 am 11:19 AM

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.

How to use thinkphp fetch method How to use thinkphp fetch method Jun 03, 2023 am 08:43 AM

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

How to use the fetch method in JavaScript How to use the fetch method in JavaScript Feb 19, 2024 pm 03:30 PM

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

How to use reflection and dynamic proxy to implement a View annotation binding library in Java How to use reflection and dynamic proxy to implement a View annotation binding library in Java Apr 30, 2023 pm 05:34 PM

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

How to request data with react fetch How to request data with react fetch Jan 05, 2023 am 10:02 AM

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.

See all articles