Fix #17929: Actions can now have bool typed params bound

This commit is contained in:
Alex
2020-03-24 15:44:43 +00:00
committed by GitHub
parent 31e3698ab9
commit 4b6d3c0290
4 changed files with 9 additions and 3 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.33 under development 2.0.33 under development
------------------------ ------------------------
- Enh #17929: Actions can now have bool typed params bound (alex-code)
- Enh #17827: Add `StringValidator::$strict` that can be turned off to allow any scalars (adhayward, samdark) - Enh #17827: Add `StringValidator::$strict` that can be turned off to allow any scalars (adhayward, samdark)
- Bug #16145: Fix `Html` helper `checkboxList()`, `radioList()`, `renderSelectOptions()`, `dropDownList()`, `listBox()` methods to work properly with traversable selection (samdark) - Bug #16145: Fix `Html` helper `checkboxList()`, `radioList()`, `renderSelectOptions()`, `dropDownList()`, `listBox()` methods to work properly with traversable selection (samdark)
- Bug #17797: Fix for `activeListInput` options (alex-code) - Bug #17797: Fix for `activeListInput` options (alex-code)

View File

@ -147,6 +147,9 @@ class Controller extends \yii\base\Controller
case 'float': case 'float':
$params[$name] = filter_var($params[$name], FILTER_VALIDATE_FLOAT, FILTER_NULL_ON_FAILURE); $params[$name] = filter_var($params[$name], FILTER_VALIDATE_FLOAT, FILTER_NULL_ON_FAILURE);
break; break;
case 'bool':
$params[$name] = filter_var($params[$name], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
break;
} }
if ($params[$name] === null) { if ($params[$name] === null) {
$isValid = false; $isValid = false;

View File

@ -59,10 +59,12 @@ class ControllerTest extends TestCase
$aksi1 = new InlineAction('aksi1', $this->controller, 'actionAksi1'); $aksi1 = new InlineAction('aksi1', $this->controller, 'actionAksi1');
$params = ['foo' => '100', 'bar' => null]; $params = ['foo' => '100', 'bar' => null, 'true' => 'on', 'false' => 'false'];
list($foo, $bar) = $this->controller->bindActionParams($aksi1, $params); list($foo, $bar, $true, $false) = $this->controller->bindActionParams($aksi1, $params);
$this->assertSame(100, $foo); $this->assertSame(100, $foo);
$this->assertSame(null, $bar); $this->assertSame(null, $bar);
$this->assertSame(true, $true);
$this->assertSame(false, $false);
$params = ['foo' => 'oops', 'bar' => null]; $params = ['foo' => 'oops', 'bar' => null];
$this->expectException('yii\web\BadRequestHttpException'); $this->expectException('yii\web\BadRequestHttpException');

View File

@ -17,7 +17,7 @@ class FakePhp7Controller extends Controller
{ {
public $enableCsrfValidation = false; public $enableCsrfValidation = false;
public function actionAksi1(int $foo, float $bar = null) public function actionAksi1(int $foo, float $bar = null, bool $true, bool $false)
{ {
} }
} }