-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add FindModelTrait, add new commands to the AppController, update act…
…ions in the UserController
- Loading branch information
Igor Chepurnoy
committed
Jul 1, 2016
1 parent
1fbf7ed
commit 9d86eec
Showing
6 changed files
with
134 additions
and
66 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace app\traits; | ||
|
||
use Yii; | ||
use yii\db\ActiveRecord; | ||
use yii\web\NotFoundHttpException; | ||
|
||
/** | ||
* Class FindModelTrait | ||
* @package app\traits | ||
*/ | ||
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 | ||
* @return ActiveRecord | ||
* @throws NotFoundHttpException | ||
*/ | ||
protected function findModel($modelClass, $condition) | ||
{ | ||
if (($model = $modelClass::findOne($condition)) !== null) { | ||
return $model; | ||
} else { | ||
throw new NotFoundHttpException($this->notFoundMessage); | ||
} | ||
} | ||
} |