标签:namespace app style sub sig extends doctype min set
这个东东,就得多练多写,无它法。
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>变量输出</title> </head> <body> <p>var: {$val}</p> <p>一维数组name: {$array1.name}</p> <p>一维数组name: {$array1[‘name‘]}</p> <p>二维数据name: {$array2[0][‘name‘]}</p> <p>标准对象name: {$obj->name}</p> <p>输出server变量: {$Think.server.request_uri}</p> <p>输出get变量: {$Think.get.name}</p> <p>输出cookie变量:{$Think.cookie.PHPSESSID}</p> <p>输出配置变量:{$Think.config.name}</p> <p>参数大于一个的函数:{$now|date=‘Y-m-d H:i:s‘, ###}</p> <p>参数等于一个的函数:{$name|strtoupper}</p> <p>函数嵌套:{$name|md5|substr=###,0,16}</p> <p>变量默认值测试:{$user.mark|default=‘此用户很懒‘}</p> <p>变量默认值+函数测试:{$Think.get.name|default=‘名称为空‘|empty|var_dump}</p> <h1>数组测试:</h1> <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,测试
标签:namespace app style sub sig extends doctype min set
原文地址:https://www.cnblogs.com/aguncn/p/11074639.html