1

I have a Product model with the following rules:

...
array('normal_price, company_id, purchase_price', 'safe', 'on' => 'adminList'),
array('normal_price, company_id', 'safe', 'on' => 'list'),
...

And I call the following function:

$product->scenario = 'list';
$product->safeAttributeNames;

The code above should only return ['normal_price, company_id'], but I get the purchase_price as well, all time. Even if I delete the first rule for the adminList scenario.

I would need the list of attributes, that I specify. What could be the problem with my code?

4

2 回答 2

1

我刚刚发现,我有一个没有场景的购买规则的长度规则。当我注释掉所有其他规则时,它可以达到我想要的效果。

描述:

要仅获取“安全”属性,您不应在该场景中为这些属性设置任何其他规则。

我的解决方案是为每个规则设置默认方案,例如:

array('id', 'require', 'on' => 'insert, update')
于 2013-06-13T23:19:29.457 回答
0

尝试使用这个:

$product->setScenario('list');
于 2013-06-13T20:22:40.530 回答