通过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:wampwww hinkphpHomeTplIndexindex.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} 花括号的意思:
定界符:
<?php
return 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 userG;
*************************** 1. row ***************************
Table: user
Create 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=utf8
1 row in set (0.00 sec)
<?php
return 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();
}
}
?>