Created
July 14, 2016 11:24
-
-
Save Mopkau/904ee08a79c18ecc322e3ee007c4f422 to your computer and use it in GitHub Desktop.
LoadModel Yii1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function loadModel($id, $class = false, $attributes = false, $prepare = true, $seo = true, $condition = '', $params = array()) | |
{ | |
if ($class === false) { | |
$class = $this->getModelClass(); | |
} | |
/** @var ActiveRecord $finder */ | |
$finder = ActiveRecord::model($class)->published(); | |
if (is_array($id) && $attributes) { | |
$model = $finder->findByAttributes($id, $condition, $params); | |
} else { | |
$model = $finder->findByPk($id, $condition, $params); | |
} | |
if ($model === null) { | |
throw new \CHttpException(404, t('The requested page does not exist.')); | |
} | |
if ($prepare) { | |
$this->prepare($model); | |
} | |
if ($seo && $model->asa('seo') && $this->asa('seo')) { | |
$this->registerSEO($model); | |
} | |
return $model; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment