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 assign () method in thinkphp

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

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "how to use the assign () method in thinkphp". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to use the assign () method in thinkphp" can help you solve your doubts.

In thinkphp, the assign () method is used to print an array. The first parameter of this method is the variable name used when the template takes the value, and the second parameter is the value to be passed, with the syntax of "$this- > assign ('name',$value);".

This article operating environment: Windows10 system, ThinkPHP5 version, Dell G3 computer.

How to use the assign () method in thinkphp

Let's start with $this- > assign ().

Its function is very simple, is to print out the array.

For example:

The first parameter in assign is the variable name used when the template takes a value, and the second parameter is the value to be passed.

Value {$apple}

This allows you to pass the value to the template.

Let's talk about $this- > display ()

Its function is to put the typed data on the corresponding template. Normally, there is no need for assignment, because it will automatically find the corresponding template file according to the naming convention. But there are always other situations, so let's talk about other situations.

First, call other templates of the current module

Format: $this- > display ('template name')

For example, if you are currently operating apple under the Table module, we need to call orange under the Table module.

Write $this- > display ('orange') like this.

Second, call the operation of other modules

Format: $this- > display ('module name: template name')

For example, suppose you are currently operating on a Table module. We need to call the pizza of the Food module.

Write $this- > display ('Food:pizza') like this.

Third, full-path output template

Format: $this- > display ('path file name')

For example, we output the add.html under the current public directory

Write $this- > display ('. / public/add.html'); like this.

4. Other parameter methods

We want to specify the encoding of the template output instead of the default encoding.

Can be used

$this- > display ('Table:apple','gbk')

Or the template is not in HTML format, but in XML format

$this- > display ('Table:apple','utf-8','text/xml'); read here, this article "how to use the assign () method in thinkphp" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

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