ThinkPHP框架视图详细介绍 View 视图-模板(9)
ThinkPHP框架视图详细介绍 View 视图--模板(九)
视图也是ThinkPHP使用的核心部分:
一、模板的使用
a、规则模板文件夹下[TPL]/[分组文件夹/][模板主题文件夹/]和模块名同名的文件夹[Index]/和方法名同名的文件[index].html(.tpl)
-->更换模板文件的后缀名(修改配置文件)
'TMPL_TEMPLATE_SUFFIX'=>'.tpl',//更改模板文件后缀名,默认是html
Tpl/Index/index.html ==> Tpl/Index_index.html (改成这种文件目录形式)
配置文件:
'TMPL_FILE_DEPR'=>'_',//修改模板文件目录层次
c、模板主题(就是网站的不同模板类似QQ装扮皮肤)
-->TP默认是没有主题的,现在模拟建立2个主题模板 my 和 your 文件夹
Home/Tpl/my/Index/index.html
Home/Tpl/your/Index/index.html
想用哪个模板主题,在配置文件中换上对应值即可
'DEFAULT_THEME'=>'your', //设置默认模板主题,访问的时候就是your模板下的index
需要在TPL下面新建一个your文件夹作为模板主题文件夹
*如何动态修改模板主题?
1、在后台准备一个功能,修改config.php文件中的默认模板项
2、通过url传递 t=主题 参数可以修改不同的模板
'DEFAULT_THEME'=>'your',//设置默认模板主题
'TMPL_DETECT_THEME'=>true,//自动侦测模板主题
'THEME_LIST'=>'your,my',//支持的模板主题列表要先建立好 my 和 your模板
设置好后这么访问,后面直接带个t参数 t/你的模板文件:
http://localhost/thinkphp/index.php/Index/index.html/t/my
http://localhost/thinkphp/index.php/Index/index.html/t/your
二、输出模板内容
a、display
1.display中没有参数
$this->display();
2.可以带参数
$this->display(本模块文件夹下的其他模板文件);
$this->display('index2');
$this->display(其他文件夹下的模板文件);
$this->display('User:index'); //本模块调用User模块的index文件
//注意,仅仅需要在Tpl下有Public文件夹以及其中的error.html即可
//不需要一定有Public模块--PublicAction.class.php
$this->display('Public:error');
$this->display(其他主题下的 文件夹下的 模板文件);
//需要开启主题支持,DEFAULT_THEME'=>'my'
$this->display('my:Index:index');
$this->display(一个url路径);
$this->display('./Public/error.html'); //public位置在网站根目录下 /public/error.html
//几乎不使用
$this->display('./Public/error.html','utf-8','text/xml'); //模板 编码 显示方式(html或xml)
$content ='这是show的使用直接传html代码';//可能是数据库啊直接拿到的输出来
$this->show($content); == $this->show('这是show的使用直接传html代码');
3.fetch方法
获得模板文件中的内容,以字符串形式返回
$content=$this->fetch('Public:error');
4.show方法
不需要模板文件,可以直接输出模板内容
$content=$this->fetch('Public:error');
dump($content);
$content=str_replace('h1','i',$content);
$this->show($content);
三、模板中的赋值 :
//$this->assign('name','乐杨俊'); 或
$this->name='乐杨俊2';
$this->display();
模板变量输出:
一、变量输出
1.标量输出 --整型 浮点型 字符型、、、
2.数组输出
$arr = array('k1'=>'leyangjun','k2'=>'leyangjun2');
$this->assign('name',$arr);
$this->display();
模板输出用:
{$name[1]} --索引数组
{$name['k2']} --关联数组 或
{$name.k1}
3.对象输出
{$name:k}
{$name->k}
二、系统变量(手册详细介绍)
//http://localhost/thinkphp/index.php/Index/add/name/leyangjun
{$Think.get.name} --url传的name值,在模板中可以直接拿到输出
{$Think.get.id}
三、使用函数(模板中对变量直接使用PHP函数)
{$name|strtoupper} 生成的编译后文件是 在生成临时文件可见
{$name|date='Y m d H:i:s',###}
四、默认值
{$name|default='这里是默认值'}
五、运算符
+ - * / % ++ --
$this->assign('name',10);
{$name++} --11

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

index.html represents the home page file of the web page and is the default page of the website. When a user visits a website, the index.html page is usually loaded first. HTML (HypertextMarkupLanguage) is a markup language used to create web pages, and index.html is also an HTML file. It contains the structure and content of a web page, as well as tags and elements used for formatting and layout. Here is an example index.html code: <

Do you see "A problem occurred" along with the "OOBELANGUAGE" statement on the Windows Installer page? The installation of Windows sometimes stops due to such errors. OOBE means out-of-the-box experience. As the error message indicates, this is an issue related to OOBE language selection. There is nothing to worry about, you can solve this problem with nifty registry editing from the OOBE screen itself. Quick Fix – 1. Click the “Retry” button at the bottom of the OOBE app. This will continue the process without further hiccups. 2. Use the power button to force shut down the system. After the system restarts, OOBE should continue. 3. Disconnect the system from the Internet. Complete all aspects of OOBE in offline mode

Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11
