We're going to learn about the thinkphp view, which is the visible content of the Web, typically HTML
The portion of data that is available to the user in conjunction with PHP, which belongs to the V in MVC
A Template definition
Default template file Definition rule: View catalog/[template Theme/] Controller name/action name + template suffix
You can set the relevant configuration to change these settings: The position of the red box is the modified position
Modify the View catalog for a template
' Default_v_layer ' = ' Template ',
To modify the suffix of a file in a template
' Tmpl_template_suffix ' = '. TPL '
Use an underscore instead of the TOC hierarchy, instead of creating a table of contents, use the linked directory file name
' Tmpl_file_depr ' = ' _ ',
Set the external template catalog
' View_path ' = './public/',
Default:
After modification:
Set the default theme directory
' Default_theme ' = ' DEFAULT ',
Toggle Theme
$this->theme (' Blue ')->display ();
Second, assignment and rendering
Assignment value:
1 // pass a variable to the template 2 $this->assign (' user ', ' crayon small new '); 3 // calling a variable in the template 4 {$user}
Rendering:
The render template output uses the display method and has three optional parameters:
display ([Template file] [, character encoding] [, output type]);
1 //do not pass parameters2 $this-display ();3./weibo/home/view/default/user/index.TPL4 //Modify the default template5 $this->display (' Add ');6./weibo/home/view/default/user/add.TPL7 //Modify the default template, catalog add template8 $this->display (' Bbb/add ');9./weibo/home/view/default/Bbb/add.TPLTen //Modify the default template, module Plus Catalog template One $this->display (' [Email protected]/add ')); A./weibo/admin/view/default/Bbb/add.TPL - //Modify the default template, Theme Plus catalog add template - $this->theme (' Blue ')->display (' Bbb/add ')); the./weibo/home/view/blue//Bbb/add.TPL - //Modifying the default template, customizing the template - $this->display ('./template/public/add.tpl ')); -./template// Public/ADD.TPL//Template and Weibo peers + //Modify the default template, specify the encoding and file type, generally do not fill, by default - $this->display (' Add ', ' utf-8 ', ' text/xml ');
If you report such a mistake, don't be fooled by it;/template/public/add.tpl.html
./weibo/home/view/./template/public/add.tpl.html
Three Template address T (), specifically for generating template files
T ([Resource://][module @][subject/][Controller/] operation, [view layering]);
The parameters of display () are somewhat similar, but more advanced. Can be combined with this method to achieve the template directory switching
Four Get Template Content-----Fetch () method
1 // get the content in the template 2 $content Fetch ($this); 3 Var_dump ($content); 4 // re-render output through content 5 $this->show ($content);
This gets the template all the code (in the form of a string), processing and then rendering the output is very powerful
Mastering the Thinkphp3.2.0----view