1. Open the URL in the browser: http://www.channel-pub-api-localhost.chinamcloud.com/weibo-oauth2/authorize-update?group_id=spider&channel_app_source_uuid=269f68bc098011e9b1c354ee75d2ebc1&user_name=华栖云1658397962&permission=4&status=1&redirect_uri=aHR0cDovL3d3dy56bXQuY29tLw%3D%3D . At this point, the validation rules take effect, as shown in Figure 1.

2. The validation rule is: permission: optional, permission, 1: sync; 2: publish; 3: sync and publish
/* 更新微博的微连接的网页应用的用户 */
[['permission'], 'in', 'range' => [self::PERMISSION_SYNC, self::PERMISSION_PUB, self::PERMISSION_SYNC_PUB], 'on' => self::SCENARIO_UPDATE],
3. At this point, the value of permission in the database is 2, and the value of updated_at is 1545961613, as shown in Figure 2.

4. Open the URL in the browser: http://www.channel-pub-api-localhost.chinamcloud.com/weibo-oauth2/authorize-update?group_id=spider&channel_app_source_uuid=269f68bc098011e9b1c354ee75d2ebc1&user_name=华栖云1658397962&permission=2&status=1&redirect_uri=aHR0cDovL3d3dy56bXQuY29tLw%3D%3D . The value of permission is 2. Because the permission field is of type SMALLINT(6) and the status field is of type SMALLINT(6), while the parameters passed through the URL are of string type, an update SQL is executed even though the values of permission and status have not changed. The executed SQL statement is as follows:
UPDATE `cpa_weibo_weibo_connect_web_app_user` SET `permission`=2, `status`=1, `updated_at`=1546066986 WHERE `id`=17
5. Adjust the validation rules to apply a filter (intval) to the input value.
/* 更新微博的微连接的网页应用的用户 */
[['permission'], 'in', 'range' => [self::PERMISSION_SYNC, self::PERMISSION_PUB, self::PERMISSION_SYNC_PUB], 'on' => self::SCENARIO_UPDATE],
[['permission', 'status'], 'filter', 'filter' => 'intval', 'on' => self::SCENARIO_UPDATE],
6. Open the URL in the browser: http://www.channel-pub-api-localhost.chinamcloud.com/weibo-oauth2/authorize-update?group_id=spider&channel_app_source_uuid=269f68bc098011e9b1c354ee75d2ebc1&user_name=华栖云1658397962&permission=&status=1&redirect_uri=aHR0cDovL3d3dy56bXQuY29tLw%3D%3D . The value of permission is an empty string. At this point, the validation rules fail, the value of permission is updated to 0, and the executed SQL statement is as follows:
UPDATE `cpa_weibo_weibo_connect_web_app_user` SET `permission`=0, `updated_at`=1546067544 WHERE `id`=17
7. Adjust the validation rules to place the filter (intval) first.
/* 更新微博的微连接的网页应用的用户 */
[['permission', 'status'], 'filter', 'filter' => 'intval', 'on' => self::SCENARIO_UPDATE],
[['permission'], 'in', 'range' => [self::PERMISSION_SYNC, self::PERMISSION_PUB, self::PERMISSION_SYNC_PUB], 'on' => self::SCENARIO_UPDATE],
8. Open the URL in the browser: http://www.channel-pub-api-localhost.chinamcloud.com/weibo-oauth2/authorize-update?group_id=spider&channel_app_source_uuid=269f68bc098011e9b1c354ee75d2ebc1&user_name=华栖云1658397962&permission=&status=1&redirect_uri=aHR0cDovL3d3dy56bXQuY29tLw%3D%3D . The value of permission is an empty string. At this point, the validation rules take effect, but its value has already changed from a string to 0. The expectation is to only convert the integer value when it is not an “empty value”, as shown in Figure 3.

9. By default, when an input is an empty string, an empty array, or null, it is considered an “empty value”. In the core validators, the filter validator processes empty input by default. Adjust the filter validator by changing its yii\base\Validator::skipOnEmpty property from false to true.
/* 更新微博的微连接的网页应用的用户 */
[['permission', 'status'], 'filter', 'filter' => 'intval', 'skipOnEmpty' => true, 'on' => self::SCENARIO_UPDATE],
[['permission'], 'in', 'range' => [self::PERMISSION_SYNC, self::PERMISSION_PUB, self::PERMISSION_SYNC_PUB], 'on' => self::SCENARIO_UPDATE],
10. Open the URL in the browser: http://www.channel-pub-api-localhost.chinamcloud.com/weibo-oauth2/authorize-update?group_id=spider&channel_app_source_uuid=269f68bc098011e9b1c354ee75d2ebc1&user_name=华栖云1658397962&permission=&status=1&redirect_uri=aHR0cDovL3d3dy56bXQuY29tLw%3D%3D . The value of permission is an empty string. At this point, the validation rules take effect, and data validation fails: Permission cannot be blank. As shown in Figure 4.

11. At this point, the order of the two rules can be adjusted freely, because both rules only execute validation when their values are not “empty values”. It is recommended to place it at the end, indicating that the integer value conversion occurs only after validation passes.
/* 更新微博的微连接的网页应用的用户 */
[['permission'], 'in', 'range' => [self::PERMISSION_SYNC, self::PERMISSION_PUB, self::PERMISSION_SYNC_PUB], 'on' => self::SCENARIO_UPDATE],
[['permission', 'status'], 'filter', 'filter' => 'intval', 'skipOnEmpty' => true, 'on' => self::SCENARIO_UPDATE],
12. Open the URL in the browser: http://www.channel-pub-api-localhost.chinamcloud.com/weibo-oauth2/authorize-update?group_id=spider&channel_app_source_uuid=269f68bc098011e9b1c354ee75d2ebc1&user_name=华栖云1658397962&permission=&status=1&redirect_uri=aHR0cDovL3d3dy56bXQuY29tLw%3D%3D . The value of permission is an empty string. At this point, the validation rules take effect, and data validation fails: Permission cannot be blank. This is consistent with the error response in step 10 and meets expectations.
