Home > PHP Framework > ThinkPHP > What is the use of the T method in thinkphp?

What is the use of the T method in thinkphp?

青灯夜游
Release: 2022-03-15 18:38:46
Original
2509 people have browsed it

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

What is the use of the T method in thinkphp?

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

In order to output template files more conveniently, thinkphp encapsulates a T function to generate template file names.

Usage:

T([资源://][模块@][主题/][控制器/]操作,[视图分层])
Copy after login

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

For example:

    T('Public/menu');
    // 返回 当前模块/View/Public/menu.html
    T('blue/Public/menu');
    // 返回 当前模块/View/blue/Public/menu.html
    T('Public/menu','Tpl');
    // 返回 当前模块/Tpl/Public/menu.html
    T('Public/menu');
    // 如果TMPL_FILE_DEPR 为 _ 返回 当前模块/Tpl/Public_menu.html
    T('Public/menu');
    // 如果TMPL_TEMPLATE_SUFFIX 为.tpl 返回 当前模块/Tpl/Public/menu.tpl
    T('Admin@Public/menu');
    // 返回 Admin/View/Public/menu.html
    T('Extend://Admin@Public/menu');
    // 返回 Extend/Admin/View/Public/menu.html (Extend目录取决于AUTOLOAD_NAMESPACE中的配置)
Copy after login

Use the T function directly in the display method:

  // 使用T函数输出模板
    $this->display(T('Admin@Public/menu'));
Copy after login

The T function can output different view layered templates.

[Related tutorial recommendations: thinkphp framework]

The above is the detailed content of What is the use of the T method in thinkphp?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template