ybt7755221 2012-08-24 11:12:34 2980次浏览 1条回复 0 0 0
$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保存了,但不用这种方法又不知道该用哪儿种,求大侠们指点

您需要登录后才可以回复。登录 | 立即注册