Browse Source

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

tags/2.0.33
Alex 5 years ago committed by GitHub
parent
commit
4b6d3c0290
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      framework/CHANGELOG.md
  2. 3
      framework/web/Controller.php
  3. 6
      tests/framework/web/ControllerTest.php
  4. 2
      tests/framework/web/FakePhp7Controller.php

1
framework/CHANGELOG.md

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
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)
- 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)

3
framework/web/Controller.php

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

6
tests/framework/web/ControllerTest.php

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

2
tests/framework/web/FakePhp7Controller.php

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

Loading…
Cancel
Save