thinkPHP learning record 4

view

Template definitions

Press the view template directory (default view) / [template theme] / name of the controller / action name + suffix stored template.

Template Theme

Each template can have a theme, it only needs an extra layer on the directory structure before view rendering output, we can change the theme template to use by dynamic setting.

       
       
1
2
       
       
// dynamically change the template theme in the controller
$this->theme('blue')->display('add');

Template assignment

The variables in the controller assigned to assign a template method requires the use of
$ this-> assihn ( 'name' , $ value)
after the assignment {$ name} can be output with the template
if the template to simultaneously output a plurality of variables

       
       
1
2
3
4
       
       
$array['name'] = 'thinkphp';
$array['email'] = '[email protected]';
$array['phone'] = '12335678';
$this->assign($array);

Output in the template as follows:

       
       
1
       
       
<?php echo $name.'['.$email.''.$phone.']';?>

If the built-in template engine, you can use:

       
       
1
       
       
{$name} [ {$email} {$phone} ]

The output of the same content.

Template Rendering

Template assignment must be operated before rendering the template

Render the template output the most commonly used method is to use the display, call format:

       
       
1
       
       
display('[ Template file ] '[ large column   thinkPHP learning record 4 Tring ">' character encoding ' ] [ ' output type ' ])

Acquisition module Address

In order to facilitate the output of the template, a new version of the package used to generate the T function template file name.

       
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
       
       
T('Public/menu');
// returns the current module /View/Public/menu.html
T('blue/Public/menu');
// returns the current module /View/blue/Public/menu.html
T('Public/menu','Tpl');
// returns the current module /Tpl/Public/menu.html
T('Public/menu');
// If TMPL _FILE_ DEPR is _ return current module / Tpl / Public_ the menu.html
T('Public/menu');
// If TMPL _TEMPLATE_ SUFFIX .tpl return to the current module /Tpl/Public/menu.tpl
T('Admin@Public/menu');
// returns Admin / View / Public / menu.html
T('Extend://Admin@Public/menu');
// returns Extend / Admin / View / Public / (Extend the directory configuration depends AUTOLOAD_NAMESPACE) the menu.html

Access to content

If you need to get the output content rendering template rather than a direct output, you can use fetch method.

       
       
1
       
       
$content = $this->fetch('Member:edit');

If you do not define any template file, or the contents of the template stored in the database, you will need to show the way to render output

       
       
1
       
       
$this->show($content, 'utf-8', 'text/xml');

Template engine

Guess you like

Origin www.cnblogs.com/dajunjun/p/11712940.html