PHP'; return$this->dieplay($con); return$this->view->display($con); returnView::display($con);//静态代理 } //使用视图将数据进行输出:fetch() publicfunctiontest2() { //模板变量赋值:assign() //1、普通变量 $this->view->assign('name','zhang'); $this->view->assign('age',23); //批量赋值 $this->view->assign([ 'sex'=>'男', 'salary'=>1200 ]); //2、array $this->view->assign('goods',[ 'id'=>1, 'name'=>'手机', 'model'=>'meta10', 'price'=>3000 ]); //3、object $obj=new\stdClass(); $obj->course='PHP'; $obj->lecture='zhang'; $this->view->assign('info',$obj); //4、const(系统常量) define('SITE_NAME','PHP'); //在模板中输出数据 //模板默认的目录位于当前模块的view目录,模板文件默认位于以当前控制器命名的目录中 return$this->view->fetch(); } }

创建视图文件夹(application\index\view)

创建模板(application\index\view\demo\test2.html)

输出变量:

{$name}
{$age}
{$sex}
{$salary}

{//输出数组} {$goods.id}
{$goods.name}
{$goods['model']}
{$goods['price']}

{//输出对象} {$info->course}
{$info->lecture}

{//输出常量} {$Think.const.SITE_NAME}

{//输出PHP系统常量} {$Think.const.PHP_VERSION}
{$Think.const.PHP_SO}

{//输出系统变量} {$Think.server.php_self}
{$Think.server.session.id}
{$Think.server.get.name}
{$Think.server.post.name}

{//输出数据库配置} {$Think.config.database.hostname}

{//输出请求变量} {$Request.get.name}
{$Request.param.name}
{$Request.path}
{$Request.root}
{$Request.root.true}
{//查询当前控制器} {$Request.controller}
{//查询当前方法} {$Request.action}
{//查询域名} {$Request.host}
{//查询ip} {$Request.ip}

更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《ZendFrameWork框架入门教程》及《PHP模板技术总结》。

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

热门推荐

1 离职横幅结婚祝福语简短
2 放假的生日祝福语简短
3 送弟弟上班祝福语简短
4 恭喜表哥结婚祝福语简短
5 生地会考简短祝福语大全
6 牡丹生日祝福语简短英语
7 深圳最美祝福语简短英文
8 翻译创意祝福语大全简短
9 定制蛋糕搞笑祝福语简短
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短