View of "35" thinkphp

Source: Internet
Author: User

1. The template definition view belongs to V in MVC. HTML is generally used in conjunction with PHP to obtain the data available to the user.
    • The files for each template are independent (the file name must be the same as the controller name)
    • Default template file rule is View Catalog/[template Theme] Controller/action name + template suffix (http://localhost/basic_thinkphp/index.php/Home/User1/index)
        // Under the Controller directory user controller under the index method input        //corresponding directory for/weibo/home/view/user1/index.html        //render template output        $ this->display ();    

User1/index.html is required in the view directory. can be rendered

Modify some of the configuration of the template. Modify in common/conf/config.php:

    // Modify the template's view directory    ' Default_v_layer ' + ' View ',     // Modify the suffix of the file in the template    ' tmpl_template_suffix ' = '. TPL ',    // use underscores instead of table of contents hierarchy    // USER_INDEX.TPL    //Set external template directory    ' view_path ' = './public/',     // set Default theme directory '    default_theme ' = ' DEFAULT ',

You can switch topics by entering this line in controller/usercontroller.class.php.:( Theme that you can modify in the configuration file)

        // Toggle Theme        $this->theme (' Blue ')->display ();
2. Assignment (assign) and rendering (display)

Thinkphp provides the assign method to assign values to template variables, regardless of which type of variable is uniformly used assign assignment

// pass a variable    to the template $this->assign (' user ', ' crayon small new '); // calling a variable    in the template {$user} // PS: This method must be used before the display () method, and the save variable is passed correctly. 

The rendering template uses the display method. The format is as follows:

    1. display ([Template file],[character encoding],[output TYPE])
    2. If you do not enter a parameter, the directory is (current module/default view directory/Current controller/current operation. html)
//do not pass parameters//./WEIBO/HOME/VIEW/DEFAULT/USER/INDEX.TPL$this-display ();//Modify the default template//./WEIBO/HOME/VIEW/DEFAULT/USER/ADD.TPL$this->display (' Add ');//Modify the default template, catalog template//./WEIBO/HOME/VIEW/DEFAULT/BBB/ADD.TPL$this->display (' Bbb/add ');//Modify the default template, module add directory Template//./WEIBO/ADMIN/VIEW/DEFAULT/BBB/ADD.TPL$this->display (' [Email protected]/add '));//Modify the default template, the theme Add directory Template//./WEIBO/HOME/VIEW/BLUE/BBB/ADD.TPL$this->theme (' Blue ')->display (' Bbb/add '));//Modify the default template, custom Templates//./TEMPLATE/PUBLIC/ADD.TPL$this->display ('./template/public/add.tpl ');//template and Weibo sibling//modify default template, specify encoding and file type, generally do not fill, default can$this->display (' Add ', ' utf-8 ', ' text/xml ')
3. Template Address

The thinkphp encapsulates a T function specifically for generating template files. The format is as follows:

    • T ([Resource://][module @][subject/][Controller/] operation, [view layering]);
// output Current template address    Echo T (); // Customize the template with all of the definitions described above:    Echo T (' Public/add ')    echo t (' [email protected] ');     Echo T (' [Email protected]/add ', ' Template '); // Direct use of the T function output    $this->display (T ());
4. Get content

If you need to get the content of the template, you can use the fetch () method, which is consistent with the display () square method.

// get the content in the template $content Fetch ($this); Var_dump ($content); // re-render output through content $this->show ($content); // PS: Use the Fetch () method to get content, primarily for the purpose of processing and filtering more complex content. It is then processed and then output by the show () method.

View of "35" thinkphp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.