class IndexAction extends Action {
function index(){
$m=new Model('user');
$arr=$m->select();
var_dump($arr[0][id]);
$this->assign('data',$name);
$this->display();
}
或者:
<?php
class IndexAction extends Action {
function index(){
#$m=new Model('user');
$m=M('user');
$arr=$m->select();
var_dump($arr[0][id]);
$this->assign('data',$name);
$this->display();
}
$m 表示模型实例:
增 -C Create $m->add()
删 -D Delete $m->delete()
改 -U Update $m->save()
查 -R Read $m->select()
<?php
class IndexAction extends Action {
function index(){
#$m=new Model('user');
$m=M('user');
$arr=$m->select();
#var_dump($arr[0][id]);
$this->assign('data',$arr);
$this->display();
}
function show(){
$this->display();
}
}
?>
读取所有数据(整个数组)分配给前台模板
前台模板遍历数组:
<!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>
<volist name='data' id='vo'></volist>
</body>
</html>
<volist name='data' id='vo'></volist> name属性就是分配的值data
$this->assign('data',$arr);分配过来的标识:
<?php
class IndexAction extends Action {
function index(){
#$m=new Model('user');
$m=M('user');
$arr=$m->select();
#var_dump($arr);
$this->assign('data',$arr);
$this->display();
}
function show(){
$this->display();
}
}
?>
<!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>
<volist name='data' id='vo'>
<{$vo.id}>---<{$vo.username}>---<{$vo.sex}><br/>
</volist>
</body>
</html>
1---zhaotongzhen---0
2---mm---1
模板可以遍历数组:
<volist name='data' id='vo'>
<{$vo.id}>---<{$vo.username}>---<{$vo.sex}><br/>
</volist>