PHP代码:
<?php
namespace Home\Controller;
use Think\Controller;
class UserController extends Controller {
    public function index(){
		$id=$_GET['id'];
		$User = M('User'); // 实例化User对象
		if(is_numeric($id)){
			$u=$User->where('id='.$id)->field('id,j_username,j_password')->find();
			//$udata['id'] = $id; $udata['j_username'] = $ulist['j_username']; $udata['j_password'] = $ulist['j_password'];
			$this->assign('u',$u);
		}
		$pageCount=10;
		// 进行分页数据查询 注意page方法的参数的前面部分是当前的页数使用 $_GET[p]获取
		$list = $User->order('j_reg_time desc')->page($_GET['p'].','.$pageCount)->select();
		$this->assign('list',$list);// 赋值数据集
		$count = $User->count();// 查询满足要求的总记录数
		$Page = new \Think\Page($count,$pageCount);// 实例化分页类 传入总记录数和每页显示的记录数
		$Page->setConfig('first','首页');
		$Page->setConfig('prev','上一页');
		$Page->setConfig('next','下一页');
		$Page->setConfig('last','尾页');
		$show = $Page->show();// 分页显示输出
		$this->assign('page',$show);// 赋值分页输出
		$this->display(); // 输出模板
    }
	
	public function add(){
		$id=$_POST['id'];
		$username=$_POST['j_username'];
		if($_POST['j_username']=='' || $_POST['j_password']==''){
			exit('用户名和密码不能为空!');
		}
		$data['j_username'] = $_POST['j_username'];
		$data['j_password'] = $_POST['j_password'];
		$data['j_reg_time'] = date('Y-m-d H:i:s');
		// 实例化User模型
		$User = M('User');
		if(is_numeric($id)){
			// 根据条件更新记录
			$User->where('id='.$id)->save($data);
			echo '会员修改成功!<a href="/index.php/Home/User/index">点击返回首页</a>';
		}else{
			$userCount = $User->where("j_username='{$data['j_username']}'")->count();
			if($userCount>0){
			exit('对不起,该会员名已经存在,请另换一个!');	
			}
			// 创建数据后写入到数据库
			$User->data($data)->add();
			echo '会员添加成功!<a href="/index.php/Home/User/index">点击返回首页</a>';
		}
	}
	
	public function del(){
		$id=$_GET['id'];
		$User = M("User"); // 实例化User对象
		$User->where('id='.$id)->delete(); // 删除id为5的用户数据
		//$User->delete('1,2,5'); // 删除主键为1,2和5的用户数据
		echo '会员删除成功!<a href="/index.php/Home/User/index">点击返回首页</a>';
	}
}
HTML代码:
<p>添加新会员</p>
<form id="form1" name="form1" method="post" action="/index.php/Home/User/add">
  <p>
    名称:
      <input type="text" name="j_username" id="j_username" value="{$u.j_username}" />
  </p>
  <p>
    密码:
      <input type="text" name="j_password" id="j_password" value="{$u.j_password}" />
  </p>
  <p>
    <input type="submit" name="button" id="button" value="提交" />
    <input type="text" name="id" id="id" value="{$u.id}" />
  </p>
</form>
<p>会员列表:</p>
<p>
<volist name="list" id="vo">
{$vo.id}:{$vo.j_username}:{$vo.j_password}:{$vo.j_reg_time} = <a href="/index.php/Home/User/index/id/{$vo.id}">修改</a> = <a href="/index.php/Home/User/del/id/{$vo.id}">删除</a><br/>
</volist>
</p>
<p>{$page}</p>