background image

5,下面针对我上面的数据表写出我的代码:
我的 Action 是这样的:UserAction.

class

.php。控制器我只对添加和查找做例子,因此代码

如下:
代码如下:
 

public

 

function

 index() { 

header("Content-Type:text/html; charset=utf-8"); 
 

$M_User

 = 

new

 UserModel(); 

 

$User_List

 = 

$M_User

->select(); 

 

$this

->assign('Title', '用户管理'); 

 

$this

->assign('UserList', 

$User_List

); 

 

$this

->display(); 


 

//

 

添加用户提交处理

public

 

function

 Create_Post() { 

$M_User

 = 

new

 UserModel(); 

$data

['username'] = 

$this

->_post('username'); 

$data

['password'] = md5(

$this

->_post('pwd')); 

 

if

 (

$M_User

->create()) { 

$Query_Result

 = 

$M_User

->add(

$data

); 

if

 (false !== 

$Query_Result

) { 

$this

->success('用户添加成功'); 

else

 { 

$this

->error('用户添加错误'); 


else

 { 

header("Content-Type:text/html; charset=utf-8"); 

exit

(

$M_User

->getError() . ' [ <a href="javascript:history.back()">

 

返 回</a> ]'); 


}
 
Action 解释: