/** * This is invoked before the record is saved. * @return boolean whether the record should be saved. */ public function beforeSave($insert) { $this->date_associated = date('Y-m-d'); if ($insert) { $this->time_create = $this->time_update = time(); } else { $this->time_update = time(); //here we check if the body has changed if ($this->body != $this->_oldBody) { $OldPage = new Page(); //looks strange, but the old page needs to be backuped into a new one;) $OldPage->body = $this->_oldBody; $OldPage->title = $this->title; $OldPage->name = $this->name; $OldPage->tags = $this->_oldTags; $OldPage->parent_pages_id = $this->id; $OldPage->special = -1; //means its a none normal page $OldPage->status = Workflow::STATUS_ARCHIVED; $OldPage->save(); } } return parent::beforeSave($insert); }
/** * Creates a new Page model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($id = NULL) { $model = new Page(); if (!is_null($id)) { $model->parent_pages_id = $id; } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(array('/pages/page/view', 'id' => $model->id)); } return $this->render('create', array('model' => $model)); }