now, those attributes on the model have no rule specified but are on the safeAttributes() list
what happened is that on first insertion with empty fields, I had the fields in the db with ‘0000-00-00 00:00 00:00’ as a value.
I tried to add something in the controller in the actionUpdate() method just to test its functionality but nothing has changed, so it seemed something related to the validation process, so I added this method in the model:
public function beforeSave() {
if (!$this->selling_start_date)
$this->selling_start_date = NULL;
if (!$this->selling_end_date)
$this->selling_end_date = NULL;
if (!$this->sale_start_date)
$this->sale_start_date = NULL;
if (!$this->sale_end_date)
$this->sale_end_date = NULL;
}
but when I’m going to submit the form, the form isn’t submitted and it keeps showing.
What’s wrong?
What’s the best way to handle NULL values from yii
what about the null values? can I gain the same result with a similar validator, but with for example ‘setOnEmpty’=>null ? I’m gonna try it, but if anyone of you have already tried and can share your own experience…
[edit] about the null, the thing is that I’d like to AVOID sending certain fields in the query. Is the only way using DAO?
ok figured it out by myself. finding the right answer in the forums (the search form on top right is crappy)
I had to add the return value at the end…
public function beforeSave() {
if (!$this->selling_end_date)
$this->selling_end_date = NULL;
if (!$this->sale_start_date)
$this->sale_start_date = NULL;
if (!$this->sale_end_date)
$this->sale_end_date = NULL;
return parent::beforeSave();;
}