Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the T method in thinkphp

Shulou Source: shulou.com Published: 2022-06-01 05:38:45 09月27日 Update

This article mainly explains "how to use the T method in thinkphp". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the T method in thinkphp.

In thinkphp, the T method is used to generate the template file name with the syntax "T ([resource: / /] [module @] [topic /] [controller /] operation, [view layering])". The return value of this method is a complete template file name, which can be directly used for rendering output by display and fetch methods.

The operating environment of this tutorial: Windows7 system, thinkphp v5.1, Dell G3 computer.

To make it easier to output template files, thinkphp encapsulates a T function to generate template file names.

Usage:

T ([resource: / /] [module @] [topic /] [controller /] operation, [view layering])

The return value of the T function is a complete template file name that can be directly used for rendering output by the display and fetch methods.

For example:

T ('Public/menu'); / return current module / View/Public/menu.html T (' blue/Public/menu'); / / return current module / View/blue/Public/menu.html T ('Public/menu','Tpl'); / / return current module / Tpl/Public/menu.html T (' Public/menu') / / return current module / Tpl/Public_menu.html T ('Public/menu') if TMPL_FILE_DEPR is _; / return current module / Tpl/Public/menu.tpl T (' Admin@Public/menu') if TMPL_TEMPLATE_SUFFIX is .tpl; / / return Admin/View/Public/menu.html T ('Extend://Admin@Public/menu') / / return Extend/Admin/View/Public/menu.html (the Extend directory depends on the configuration in AUTOLOAD_NAMESPACE)

Use the T function directly in the display method:

/ / use T function to output template $this- > display (T ('Admin@Public/menu'))

The T function can output different view hierarchical templates.

At this point, I believe you have a deeper understanding of "how to use the T method in thinkphp". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Methods modules templates functions files output file names views themes content controllers resources learning control generation different practical deeper interest depending on Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi NVidia Shulou Tech Info MariaDB Shulou Technology