Commit c5022203 by Carsten Brandt

fixed issue with null value in CRUD controller findModel()

parent 74a74c84
......@@ -5,6 +5,7 @@ Yii Framework 2 gii extension Change Log
----------------------------
- Bug #1405: fixed disambiguation of relation names generated by gii (qiangxue)
- Bug: fixed controller in crud template to avoid returning query in findModel() (cebe)
- Enh #1624: generate rules for unique indexes (lucianobaraglia)
- Enh #1818: Do not display checkbox column if all rows are empty (johonunu)
......
......@@ -140,15 +140,18 @@ class <?= $controllerClass ?> extends <?= StringHelper::basename($generator->bas
<?php
if (count($pks) === 1) {
$condition = '$id';
// find() would return Query when $id === null
$nullCheck = '$id !== null && ';
} else {
$condition = [];
foreach ($pks as $pk) {
$condition[] = "'$pk' => \$$pk";
}
$condition = '[' . implode(', ', $condition) . ']';
$nullCheck = '';
}
?>
if (($model = <?= $modelClass ?>::find(<?= $condition ?>)) !== null) {
if (<?= $nullCheck ?>($model = <?= $modelClass ?>::find(<?= $condition ?>)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment