ybt7755221 2012-08-23 12:07:46 2971次浏览 9条回复 0 0 0

1.在保存成功后,提示lastInsertID未定义

$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);   
$userId = Yii::app()->user->id;
$is_comment = Yii::app()->params['is_comment'];
$modified = time();
$cate_order = 0;
$comment_count = 0;
$command->bindParam(":excerpt",trim($_POST['Posts']['excerpt']));   
$command->bindParam(":title",trim($_POST['Posts']['title'])); 
$command->bindParam(":content",CHtml::encode($_POST['Posts']['content'])); 
$command->bindParam(":type",$_POST['Posts']['type']); 
$command->bindParam(":author",$userId); 
$command->bindParam(":comment_status",$is_comment); 
$command->bindParam(":post_password",md5($_POST['Posts']['post_password'])); 
$command->bindParam(":modified",$modified); 
$command->bindParam(":post_cate",$_POST['Posts']['post_cate']); 
$command->bindParam(":cate_order",$cate_order); 
$command->bindParam(":comment_count",$comment_count); 
if($command->execute())
    $this->redirect(array('view','id'=>$command->lastInsertID));

2.DAO 保存的时候如何使用model里的rules验证?

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