public function run()
{
$modelClass = $this->modelClass;
$model = new $this->modelClass($this->modelScenario);
$controller = $this->getController();
if ($this->layout !== null) {
$layout = $controller->layout;
$controller->layout = is_callable($this->layout) ? call_user_func($this->layout) : $this->layout;
}
$this->onBeforeRender($event = new CEvent($this));
if (!$event->handled) {
if (($data = Yii::app()->request->getPost(get_class($model))) !== null) {
$model->setAttributes($data);
if ($model->save()) {
Yii::app()->user->setFlash(YFlashMessages::SUCCESS_MESSAGE, $this->getSuccessMessage());
if (!isset($_POST['submit-type'])) {
/* if returnUrl is null set them to current url */
$returnUrl = $this->returnUrl ?: Yii::app()->request->requestUri;
/* If this is callable, call it. */
$returnUrl = is_callable($returnUrl) ? call_user_func($returnUrl, $model) : $returnUrl;
$controller->redirect($returnUrl);
} else {
$controller->redirect([$_POST['submit-type']]);
}
}
}
$controller->render(is_callable($this->view) ? call_user_func($this->view, $model) : $this->view, ['model' => $model]);
$this->onAfterRender(new CEvent($this));
}
if ($this->layout !== null) {
$controller->layout = $layout;
}
}