/** * Saves or deletes the view in the db if necessary */ private function saveView() { $model = ContentMetadata::model()->findByAttributes(array('content_id' => $this->id, 'key' => 'view')); // If we don't have anything in ContentMetadata and the layout file is blog if ($model === NULL && $this->viewFile === 'blog') { return; } if ($model === NULL) { $model = new ContentMetadata(); $model->content_id = $this->id; $model->key = 'view'; } // If this is an existing record, and we're changing it to blog, delete it instead of saving. if ($this->viewFile == 'blog' && !$model->isNewRecord) { return $model->delete(); } $model->value = $this->viewFile; return $model->save(); }