我无法理清为什么设置默认值对我不起作用.
这是我的控制器:
class QueryController extends ActiveController { public $modelClass = 'app\models\Query'; public $createScenario = 'restCreate'; public $updateScenario = 'restUpdate';
我没有覆盖默认createAction
方法.
模型:
class Query extends ActiveRecord {public function rules() { return [ [['userId', 'name', 'created', 'isOneTime', 'isArchived', 'settings', 'engine'], 'required'], [['userId'], 'integer'], [['name', 'settings', 'schedule'], 'string'], [['created', 'lastUpdate'], 'safe'], [['isOneTime', 'isArchived', 'isApi', 'valid'], 'boolean'], [['state', 'engine'], 'string', 'max' => 160], [['isApi'], 'default', 'value'=> false], [['isApi'], 'default', 'value'=> true, 'on' => 'restCreate'] ]; } public function scenarios() { $scenarios = parent::scenarios(); $scenarios['restCreate'] = ['name', 'state', 'isApi', 'isOneTime', 'settings', 'schedule']; $scenarios['restUpdate'] = ['name', 'state', 'isOneTime', 'settings', 'schedule' ]; return $scenarios; }
当我通过Rest控制器创建一个新条目时,它应该isApi = true
默认设置,但它不能以这种方式工作.如何根据方案分配默认模型值?