public function run()
{
$modelClass = $this->modelClass;
/* @var $model YModel */
$model = new $modelClass($this->modelScenario);
$model->unsetAttributes();
if (($data = Yii::app()->request->getParam(get_class($model))) !== null) {
$model->setAttributes($data);
}
$controller = $this->getController();
if ($this->layout !== null) {
$layout = $controller->layout;
$controller->layout = is_callable($this->layout) ? call_user_func($this->layout, $model) : $this->layout;
}
$this->onBeforeRender($event = new CEvent($this));
if (!$event->handled) {
$dataProvider = $model->search();
if (empty($dataProvider) || !$dataProvider instanceof CActiveDataProvider) {
throw new CException("{$modelClass} should return CActiveDataProvider instance.");
}
$criteria = $dataProvider->criteria;
$criteria->mergeWith($this->criteria);
$dataProviderClass = $this->dataProviderClass;
$dataProvider = new $dataProviderClass($model, CMap::mergeArray(['criteria' => $criteria], $this->dataProviderConfig));
$controller->render(is_callable($this->view) ? call_user_func($this->view, $model) : $this->view, ['dataProvider' => $dataProvider, 'model' => $model]);
$this->onAfterRender(new CEvent($this));
}
if ($this->layout !== null) {
$controller->layout = $layout;
}
}