/** * @return \yii\db\ActiveQuery */ public function getTblPosts() { return $this->hasMany(TblPost::className(), ['author_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getPost() { return $this->hasOne(TblPost::className(), ['id' => 'post_id']); }
public function actionPostForm() { $model = new TblPost(); // uncomment the following code to enable ajax-based validation /* if(isset($_POST['ajax']) && $_POST['ajax']==='tbl-post-postForm-form') { echo CActiveForm::validate($model); Yii::app()->end(); } */ if (isset($_POST['TblPost'])) { $model->attributes = $_POST['TblPost']; $model->setAttribute('author_id', Yii::app()->user->id); if ($model->validate()) { $model->save(); } } $this->render('postForm', array('model' => $model)); }