One template ThinkPHP

This stuff, much more practice to write, it is not law.

1,Application\Home\Controller\IndexController.class.php

<?php
namespace Home\Controller;
use Home\Model\PostModel;
use Home\Model\PostViewModel;
use Home\Model\UserModel;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $val = 'name';
        $array1 = array(
            'name' => 'admin_array1'
        );
        $array2 = array(
            array('name' => 'admin_array2'),
            array('name' => 'admin_array2'),
        );

        $user = array(
          'nickname' => 'Guest',
          'mark' => '',
        );
        $userArray = array(
            'age' => 100,
        );

        $obj = new \stdClass();
        $obj->name = 'admin_obj';

        $userObj = new \stdClass();
        $userObj->age = 100;

        $this->assign('val', $val);
        $this->assign('array1', $array1);
        $this->assign('array2', $array2);
        $this->assign('userArray', $userArray);
        $this->assign('userObj', $userObj);
        $this->assign('obj', $obj);
        $this->assign('user', $user);
        $this->assign('name', 'test');
        $this->assign('now', time());
        $this->display();
    }



}

2,Application\Home\View\Index\index.html

<! DOCTYPE HTML> 
<HTML lang = "EN"> 
<head> 
    <Meta charset = "UTF-. 8"> 
    <title> Variable Output </ title> 
<head /> 
<body> 
<P> var : { $ Val } </ P> 
<P> one-dimensional array name: { $ array1 .name} </ P> 
<P> one-dimensional array name: { $ array1 [ 'name']} </ P> 
<P> dimensional data name: { $ array2 [0] [ 'name']} </ P> 
<P> standard object name: { $ obj -> name} </ P> 
<P> variable output server: { $ of Think .server.request_uri } </ P> 
<P> output variables get: { $ of Think .get.name} </ P>
<p> cookie variable Output: { $ of Think .cookie.PHPSESSID} </ P> 
<p> Output configuration variables: { $ of Think} .config.name </ P> 
<P> parameter is larger than a function: { $ now | DATE = 'Ymd H: I: S', # ##} </ P> 
<P> parameter is equal to a function of: { $ name | the strtoupper } </ P> 
<P> nested function: { $ name | MD5 | substr = # ##, 0,16} </ P> 
<P> variable default test: { $ User .mark | default = 'user lazy'} </ P> 
<P> variable default + function test: { $ of Think .get.name | default = 'name is empty' | empty | var_dump } </ P> 
<h1 of > array testing: </ h1 of> 
<P> '+' =>{$userArray['age']+1}</p>
<p>'-'=> {$userArray['age']-1}</p>
<p>'*'=> {$userArray['age']*2}</p>
<p>'/'=> {$userArray['age']/2}</p>
<p>'%'=> {$userArray['age']%2}</p>
<h1>对象测试:</h1>
<p>'+'=> {$userObj->age+1}</p>
<p>'-'=> {$userObj->age-1}</p>
<p>'*'=> {$userObj->age*2}</p>
<p>'/'=> {$userObj->age/2}</p>
<p>'%'=> {$userObj->age%2}</p>

</body>
</html>

3, the test

Guess you like

Origin www.cnblogs.com/aguncn/p/11074639.html