Methods for calling session data in ThinkPHP templates

  • 2021-07-06 10:21:49
  • OfStack

There are many methods to call session data in the template of ThinkPHP framework, which can be used flexibly according to the situation. The common ones are as follows:

1. Call {$Think. session} directly in the template to get session;

2. In < php > < /php > Tag directly writes php code to call $_ SESSION data;

3. Write in the template < ?php ? > And then write php code directly inside to call $_ SESSION;

4. Assign the $_SESSION variable to the template through the assign () method in Action;

5. In the custom function library, create a new function to return $_SESSION variable, and then assign the $_SESSION returned by the function to a variable in the template file by using {$variable name}

In addition to the above five methods, readers can also develop new calling methods according to their own preferences.

For more readers interested in thinkPHP related contents, please check the topics of this site: "ThinkPHP Introduction Tutorial", "thinkPHP Template Operation Skills Summary", "ThinkPHP Common Methods Summary", "smarty Template Introduction Basic Tutorial" and "PHP Template Technology Summary".

I hope this article is helpful to the PHP programming based on ThinkPHP framework.


Related articles: