繁甘泉辨嘛孔晤伪饥戈判蹦芹
注意:先将config目录下的字符替换删除再进行下列步骤
D:\phpStudy\PHPTutorial\WWW\tp5\application\index\controller\Index.php:
<?php namespace app\index\controller; class Index extends \think\Controller { public function index() { //创建数组变量 $user=[ 'name'=>'萌面人', 'age'=>22 ]; //创建对象变量 $book=new \stdClass(); $book->name="PHP设计模式"; $book->price=99; //变量赋值 $this->assign('domain','www.xuexianswer.com');//普通变量 $this->assign('user',$user);//数组变量 $this->assign('book',$book);//对象变量 //渲染模板 return $this->fetch(); } }
D:\phpStudy\PHPTutorial\WWW\tp5\application\index\view\index\index.html:
<p>我是index控制器index操作的模板文件</p> <p>网站域名:<span style="color: red;">{$domain}</span></p> <p>我的姓名:<span style="color: red;">{$user.name}</span></p> <p>我的姓名:<span style="color: red;">{$user['name']}</span></p> <p>我的年龄:<span style="color: red;">{$user.age}</span></p> <p>我的年龄:<span style="color: red;">{$user['age']}</span></p> <p>书的名称:<span style="color: red;">{$book:name}</span></p> <p>书的名称:<span style="color: red;">{$book->name}</span></p> <p>书的价格:<span style="color: red;">{$book:price}</span></p> <p>书的价格:<span style="color: red;">{$book->price}</span></p>
执行:
矗但伺该事弟漆绩嘲甫齐攫吮