在存在用户模型的情况下实例化一个用户类的时
分类:美高梅网上注册平台

本文以实例形式讲述ThinkPHP实现的包括用户的注册、登录以及留言等功能,这里需要大家注意的是,在存在用户模型的情况下实例化一个用户类的时候使用D方法来实现。UserActiion.class.php页面:

create();$result = $user->add{$this->assign("jumpUrl","__APP__/index/index");$this->success;}else{//echo $user->getError();$this->assign("jumpUrl","__APP__/user/register");$this->error;}}public function register;}public function login;}public function checklogin(){$username = $_POST['username'];$passwd = $_POST['passwd'];$user = D;//$User->where;这里的where 语句要注意一下,如果是其他字段的话后面一定要有单引号$userinfo = $user->where("username ='$username'")->find();if{if($userinfo['passwd'] == $passwd){Cookie::set('userid',$userinfo['id'],time;Cookie::set('username',$username,time;Cookie::set('lastlogintime',time;$this->assign("jumpUrl","__APP__/index/index");$this->success;}else{$this->assign("jumpUrl","__APP__/user/login");$this->error;}}else{$this->assign("jumpUrl","__APP__/user/login");$this->error;}}public function loginout(){Cookie::delete;Cookie::delete;$this->assign("jumpUrl","__APP__/index/index");$this->success;}} 

IndexAction.class.php页面:

create{$this->assign("jumpUrl","__URL__/index");$this->error;//如果创建失败,表示验证没有通过,输出错误信息}else{//验证通过,进行其他操作$content->userid=Cookie::get;$content->add();$this->assign("jumpUrl","__URL__/index");$this->success;}} // 数据查询操作 public function index() {$content = new ContentModel();$list = $content->findAll(); //用户的cookie$username = Cookie::get;$lastlogintime = Cookie::get;$this->assign; $this->assign;$this->assign;$this->assign('lastlogintime',$lastlogintime);$this->display(); } // 删除操作public function delete(){$content = new ContentModel();$id = $_GET['id'];if($content->where{$this->assign("jumpUrl","__URL__/index");$this->success;}else{$this->assign("jumpUrl","__URL__/index");$this->error;}} // 编辑操作public function edit(){$content = new ContentModel();$id = $_GET['id'];if{//$data = $content->select;$data = $content->where;if{$this->assign;}else{echo "数据为空!";}}$this->assign;$this->display();}// 更新操作public function update(){$content = new ContentModel,自动会帮你进行数据的传值/*$content->create; // 根据条件保存修改的数据echo "更新数据成功!";*/// 使用post 传值过来,进行更新$id = $_POST['id'];if{$data['id'] = $id;$data['title'] = $_POST['title'];$data['content'] = $_POST['content'];if)// 根据条件保存修改的数据{$this->assign("jumpUrl","__URL__/index");$this->success;}else{$this->assign("jumpUrl","__URL__/index");$this->success;}}else{echo "保存数据失败!";}}}?> 

ContentModel.class.php页面:

美高梅4858app美高梅网上注册平台 ,UserModel.class.php页面:

这里需要注意的是,使用自动验证的时候 实例化时要用 $user = D 而不能用 $user = M,用M这种方法会报错,D函数用于实例化Model,M函数用户实例化一个没有模型的文件。success.html页面:

信息提示信息提示

{$message}
2秒后返回指定页面!
如果浏览器无法跳转,请点击此处。

本文由美高梅网上注册平台发布于美高梅网上注册平台,转载请注明出处:在存在用户模型的情况下实例化一个用户类的时

上一篇:没有了 下一篇:没有了
猜你喜欢
热门排行
精彩图文