作者:嘿可爱无罪 | 来源:互联网 | 2013-08-06 09:38
1、配置项目
在conf目录下面的config.php是配置文件,可以用来配置数据库信息。
return array(
//'配置项'=>'配置值'
'DB_TYPE'=>'mysql',
'DB_HOST'=>'localhost',
'DB_NAME'=>'haqiu',
'DB_USER'=>'root',
'DB_PWD'=>'',
'DB_PREFIX'=>'blog_',
//'DEFAULT_THEME'=>'default',
);
?>
2、模板定义
3、模型定义
class loginModel extends Model{
protected $_validate = array(
array('username','checkname','用户名不能为空!',0,'callback',1),
array('username','','该账号已存在!',0,'unique',1),
array('password','checkpwd','密码至少六位!',0,'callback'),
array('repassword','password','确认密码不正确!',1,'confirm'),
array('email','checkemail','邮箱格式不正确!',0,'callback'),
);
public function checkname(){
$name =$_POST["username"];
if ($name==null){
returnfalse;
}
else {
returntrue;
}
}
public function checkpwd(){
$pwdlen =strlen($_POST["password"]);
if($pwdlen<6){
returnfalse;
}
else {
returntrue;
}
}
public function checkemail(){
$email = $_POST["email"];
$a =substr_count($email,'@');
if ($a==1){
returntrue;
}
else {
returnfalse;
}
}
protected $_auto = array(
array('password','md5',1,'function'),
);
}
?>
4、逻辑
在项目的Lib\Action目录下自动生成的IndexAction.class.php文件,这个文件就是控制器,完成Index的模块实现。删除IndexAction类默认生成的Index方法,添加新的方法:
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action{
public function zhuce(){
$this->display();
}
public function insertUser(){
$user=D("login");
$vo =$user->create();
if($vo != false){
$user->add();
$this->redirect('login');
}else{
echo$user->getError();
}
}
publicfunction login(){
$this->display();
}
public function userlogin(){
$user=M("login");
//echo$_POST["username"];
//
$vo =$user->create();
$condition["username"] =$vo['username'];
//echo$condition["username"];
//var_dump($vo);
//exit;
$usercheck =$user->where($condition)->findAll();
//var_dump ($usercheck);
// echo $usercheck[0]["password"];
//$usercheck =$user->getByName($vo['username']);
//var_dump ( $usercheck);
if ($usercheck==null){
echo"用户名不存在";
}
elseif($usercheck[0]["password"]!=md5($vo["password"])){
echo "密码输入错误!";
}
else {
setCOOKIE('user_id',$usercheck[0]["id"],time()+3600);
$this->redirect('edit');
}
}
public function edit(){
//var_dump($_COOKIE["user_id"]);
$this->display();
}
public function insertblog(){
$diary=D("diary");
$vo=$diary->create();
if($vo != false){
$diary->add();
$this->redirect('show');
}else{
echo$diary->getError();
}
}
publicfunction show(){
$diary = D("diary");
$board = D("board");
$condition["userID"] = $_COOKIE["user_id"];
$list =$diary->where($condition)->order('iddesc')->find();
//setCOOKIE("diaryID",$list[0]["id"],time()+3600);
$_SESSION["diaryID"]=$list["id"];
echo"主题:".$list["title"]." 时间:".$list["datetime"].'
';
echo"内容:".$list["content"].'
';
echo"***********************************************
";
//var_dump($_SESSION["diaryID"]);
$conditionBoard["diaryID"] =$_SESSION["diaryID"];
$boardlist =$board->where($conditionBoard)->order('iddesc')->findAll();
foreach ($boardlist as$value){
echo$value["username"]." ".$value["creat_time"].'
';
echo$value["content"].'
';
echo"____________________________________________
";
}
$this->display();
}
public function boardinsert(){
$board = D("board");
$vo =$board->create();
if($vo != false){
$board->add();
echo"评论成功!";
$this->redirect('show');
}
else{
echo$diary->getError();
}
}
}
?>