Skip to content

Commit

Permalink
Update FindModelTrait.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Chepurnoy committed Jul 4, 2016
1 parent 9d86eec commit 5f1000f
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions traits/FindModelTrait.php
Expand Up @@ -12,25 +12,22 @@
*/
trait FindModelTrait
{
/**
* @var string message for the NotFoundHttpException
*/
protected $notFoundMessage = 'The requested page does not exist.';

/**
* Finds model
*
* @param $modelClass ActiveRecord
* @param mixed $condition primary key value or a set of column values
* @param string $notFoundMessage
* @return ActiveRecord
*
* @throws NotFoundHttpException
*/
protected function findModel($modelClass, $condition)
protected function findModel($modelClass, $condition, $notFoundMessage = 'The requested page does not exist.')
{
if (($model = $modelClass::findOne($condition)) !== null) {
return $model;
} else {
throw new NotFoundHttpException($this->notFoundMessage);
throw new NotFoundHttpException($notFoundMessage);
}
}
}
}

0 comments on commit 5f1000f

Please sign in to comment.