添加不进去数据 [ 新手入门 ]
$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'),
);
}
共 5 条回复
-
fairy_demon 回复于 2011-07-28 10:35 举报
我直接用的form标签
-
lz19881123 回复于 2011-07-31 22:57 举报
学习了,呵呵
fairy_demon 廣州
注册时间:2011-05-16
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝1
- 金钱225
- 威望0
- 积分225