示例#1
0
文件: User.php 项目: Atsumoriso/Yii
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTblPosts()
 {
     return $this->hasMany(TblPost::className(), ['author_id' => 'id']);
 }
示例#2
0
 /**
  * @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));
 }