Thanks for the reply. Please look at my last comment. i wanted to add a default value as mentioned. is it possible ? btw is it a good practice to use the first method you said ?
It’s hard to say from the code you’ve provided, but if you’re just trying to set a default in certain circumstances, you could replace your default validator with a custom validation function like so:
public function rules()
{
...
array('coupon_count', 'setCouponCountDefault'),
...
}
public function setCouponCountDefault($attribute, $params)
{
if ($shouldSetDefault)
{
if ($this->coupon_count === null || $this->coupon_count === '')
$this->coupon_count = -1;
}
}
Obviously, replace the above with relevant tests.
If you know before instantiating the model whether the default should apply or not, you can use scenarios instead.