DAO关于验证的问题。 [ 新手入门 ]
$userId = Yii::app()->user->id;
$is_comment = Yii::app()->params['is_comment'];
$password = $_POST['Posts']['post_password'] ? md5($_POST['Posts']['post_password']) : '';
$modified = time();
$cate_order = 0;
$comment_count = 0;
$sql = 'INSERT INTO `{{Posts}}` (`excerpt`,`title`, `content`, `type`, `author`, `comment_status`, `post_password`, `modified`, `post_cate`, `cate_order`, `comment_count`) VALUES (:excerpt, :title, :content, :type, :author, :comment_status, :post_password, :modified, :post_cate, :cate_order, :comment_count)';
$command = Yii::app()->db->createCommand($sql);
$command->bindParam(":excerpt",trim($_POST['Posts']['excerpt']),PDO::PARAM_STR);
$command->bindParam(":title",trim($_POST['Posts']['title']),PDO::PARAM_STR);
$command->bindParam(":content",$_POST['Posts']['content'],PDO::PARAM_STR);
$command->bindParam(":type",$_POST['Posts']['type'],PDO::PARAM_INT);
$command->bindParam(":author",$userId,PDO::PARAM_INT);
$command->bindParam(":comment_status",$is_comment,PDO::PARAM_INT);
$command->bindParam(":post_password",$password,PDO::PARAM_STR);
$command->bindParam(":modified",$modified,PDO::PARAM_INT);
$command->bindParam(":post_cate",$_POST['Posts']['post_cate'],PDO::PARAM_INT);
$command->bindParam(":cate_order",$cate_order,PDO::PARAM_INT);
$command->bindParam(":comment_count",$comment_count,PDO::PARAM_INT);
if($model->validate() && $command->execute())
$this->redirect(array('view','id'=>Yii::app()->db->lastInsertID));
关于这个验证应该怎么写?如果用$model->validate()
那么就必须$model->attributes = $_POST['Posts']
那就不如直接用ar保存了,但不用这种方法又不知道该用哪儿种,求大侠们指点
ybt7755221 山东烟台
注册时间:2011-07-26
最后登录:2018-02-08
在线时长:2小时37分
最后登录:2018-02-08
在线时长:2小时37分
- 粉丝1
- 金钱570
- 威望0
- 积分590