fairy_demon 2011-07-28 10:21:51 3528次浏览 5条回复 0 0 0
$article = new Article;
//$article->attributes=$_POST['Article'];
$article->title=$_POST['Article']['title'];
$article->content=$_POST['Article']['content'];
$article->user_id=Yii::app()->user->id;
$article->submit_date=date('Y-m-d');
$article->composition_id=(int)$_POST['Article']['id'];
$article->save();

这样是添加单条数据进数据库吗,我数据库里面字段全部设置允许为空,怎么天天不进去数据 model裏面是這樣的

public function rules()
{
  // NOTE: you should only define rules for those attributes that
  // will receive user inputs.
  return array(
    array('user_id,composition_id,views, popularity, scores, word_count,recommened', 'numerical', 'integerOnly'=>true),
    array('submit_date', 'length', 'max'=>25),
    array('comments,title', 'length', 'max'=>255),
    array('recommened', 'length', 'max'=>10),
    array('mark_content,content', 'safe'),
      // The following rule is used by search().
      // Please remove those attributes that should not be searched.
array('id, title,composition_id,user_id, views, popularity, submit_date, scores, comments, content, mark_content, recommened, word_count', 'safe', 'on'=>'search'),
  );
}
您需要登录后才可以回复。登录 | 立即注册