ThinkPHP 3.1.2 输出和模型使用1

来源:互联网 发布:python中字符串的函数 编辑:程序博客网 时间:2024/06/01 09:20
通过display方法输出想分配变量可以使用assign方法方法调用模板:C层调用V层http://localhost/thinkphp/index.php模板不存在[./Home/Tpl/Index/index.html]<!doctype html><html lang="en"> <head>  <meta charset="UTF-8">  <meta name="Generator" content="EditPlus?">  <meta name="Author" content="">  <meta name="Keywords" content="">  <meta name="Description" content="">  <title>Document</title> </head> <body>  <h1>scan hello world!!!</h1> </body></html>C控制V页面输出寻找模板的规律:Index模块/index方法C:\wamp\www\thinkphp\Home\Tpl\Index\index.html                              模块名\方法名访问show方法:<!doctype html><html lang="en"> <head>  <meta charset="UTF-8">  <meta name="Generator" content="EditPlus?">  <meta name="Author" content="">  <meta name="Keywords" content="">  <meta name="Description" content="">  <title>Document</title> </head> <body>  <h1>访问show!!!</h1> </body></html><?php class IndexAction extends Action { function index(){ $name='scan'; $this->assign('data',$name); $this->display(); } 将$name分配给标识 data分配给前台模板:<!doctype html><html lang="en"> <head>  <meta charset="UTF-8">  <meta name="Generator" content="EditPlus?">  <meta name="Author" content="">  <meta name="Keywords" content="">  <meta name="Description" content="">  <title>Document</title> </head> <body>  <h1>{$data} hello world {$data}!!!</h1> </body></html>{$data} hello world {$data} 花括号的意思:定界符:<?phpreturn array(//'配置项'=>'配置值''TMPL_L_DELIM'=>'<{',   //配置左定界符'TMPL_R_DELIM'=>'}>',    //配置右定界符'DB_PREFIX'=>'',     //设置表前缀'DB_DSN'=>'mysql://root:1234567@10.10.17.2:3306/devops', //DSN方式配置数据库信息'SHOW_PAGE_TRACE'=>true,//开启页面Trace);?>修改定界符:mysql> show create table user\G;*************************** 1. row ***************************       Table: userCreate Table: CREATE TABLE `user` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `username` varchar(30) DEFAULT NULL,  `sex` int(11) DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf81 row in set (0.00 sec)<?phpreturn array(//'配置项'=>'配置值''TMPL_L_DELIM'=>'<{',   //配置左定界符'TMPL_R_DELIM'=>'}>',    //配置右定界符'DB_PREFIX'=>'',     //设置表前缀'DB_DSN'=>'mysql://root@127.0.0.1:3306/thinkphp', //DSN方式配置数据库信息'SHOW_PAGE_TRACE'=>true,//开启页面Trace);?>array (size=2)  0 =>     array (size=3)      'id' => string '1' (length=1)      'username' => string 'zhaotongzhen' (length=12)      'sex' => string '0' (length=1)  1 =>     array (size=3)      'id' => string '2' (length=1)      'username' => string 'mm' (length=2)      'sex' => string '1' (length=1)hello world<?php class IndexAction extends Action { function index(){ $m=new Model('user'); $arr=$m->select(); var_dump($arr[0]['username']); $this->assign('data',$name); $this->display(); }  function show(){ $this->display(); }}?>

原创粉丝点击