作者:五指间的节拍 | 来源:互联网 | 2014-06-12 18:37
表aoli_user字段:idusernamepasswordcreatetimecreateipaoli/Home/Tpl/default/User/index.html:<formaction"__URL__/add...
表aoli_user字段:
id username password createtime createip
aoli/Home/Tpl/default/User/index.html:
- <form action="__URL__/add" method="post">
- 用户名:<input type="text" name="username" /><br />
- 密码:<input type="password" name="password" /><br />
- 重复密码:<input type="repassword" name="repassword" /><br />
- <input type="submit" value="注册" />
- form>
- <volist name="alist" id="vo">
- <li><span>ID:span>{$vo[&#39;id&#39;]}<span>用户名:span>{$vo[&#39;username&#39;]}<span>注册ip:span>{$vo[&#39;createip&#39;]}<a href="__URL__/del/id/{$vo[&#39;id&#39;]}">删除a> <a href="__URL__/edit/id/{$vo[&#39;id&#39;]}">编辑a>li>
- volist>
aoli/Home/Tpl/default/User/edit.html:
- <form action="__URL__/update" method="post">
- 用户名:<input type="text" name="username" value="{$data[&#39;username&#39;]}" /><br />
- 密码:<input type="password" name="password" value="{$data[&#39;password&#39;]}" /><br />
- IP:<input type="text" name="createip" value="{$data[&#39;createip&#39;]}" /><br />
- 时间:<input type="text" name="createtime" value="{$data[&#39;createtime&#39;]}" /><br />
- <input type="hidden" value="{$data[&#39;id&#39;]}" name="id" />
- <input type="submit" value="更新" />
- form>
aoli/Home/Lib/Action/UserAction.class.php:
- class UserAction extends Action {
- function index(){
- $user=M(&#39;user&#39;);
- $list=$user->field(array(&#39;id&#39;,&#39;username&#39;,&#39;createip&#39;))->select();
- $this->assign(&#39;title&#39;,&#39;thinkphp视频演示&#39;);
- $this->assign(&#39;alist&#39;,$list);
- $this->display();
- }
-
- function del(){
- $user=D(&#39;user&#39;);
- if($user->delete($_GET[&#39;id&#39;])){
- $this->success(&#39;删除成功&#39;);
- }else{
- $this->error(&#39;删除失败&#39;);
- }
- }
-
- function add(){
- Load(&#39;extend&#39;);
- if($_POST[&#39;password&#39;]!=$_POST[&#39;repassword&#39;]){
- $this->error(&#39;两次密码不一致&#39;);
- }
- $user=D(&#39;user&#39;);
- if($vo=$user->create()){
- $user->password=md5($user->password);
- $user->createtime=time();
-
- $user->createip=get_client_ip();
- if($user->add()){
- $this->success(&#39;用户注册成功,返回上级页面&#39;);
- }else{
- $this->error(&#39;用户注册失败,返回上级页面&#39;);
- }
- }else{
- $this->error($user->getError());
- }
- }
-
- function edit(){
- $user=M(&#39;user&#39;);
- $id=(int)$_GET[&#39;id&#39;];
- $list=$user->where("id=$id")->find();
- $this->assign(&#39;data&#39;,$list);
- $this->assign(&#39;title&#39;,&#39;显示用户编辑信息&#39;);
- $this->display();
- }
-
- function update(){
- $user=M(&#39;user&#39;);
- $user->password=md5($user->password);
- if($user->create()){
- if($insertid=$user->save()){
- $this->success(&#39;更新成功,受影响的行数为&#39;.$insertid);
- }else{
- $this->error(&#39;更新失败&#39;);
- }
-
- }
- }
- }