This may seem weird at a first sight.
We wish to allow the user to SAVE INTO DATABASE, even if, some required fields are missing.
Then, when the user wishes to PUBLISH those records, it should NOT be allowed, because those required fields are missing.
Perhaps, create some sort of required variation that tell us:
Required for PUBLISHING but not for INSERTING;
Taking into consideration your Yii knowledge, is there some sort of pattern we should use on this case?
UPDATE
Scenarios seems to be a nice approach, but the documentation suggests adding:
$model = new MyActiveRecord('Inserting');
On our controller.
On my controller, I have, however, this:
public function actionCreate()
{
$this->layout = 'admin';
$model=new HsGuestbook;
$localized[] = $this->getExtraModelGuestTr();
if(isset($_POST['HsGuestbook']))
{
...
So, I’ve tried to do:
if(isset($_POST['HsGuestbook']))
{
//check validation scenarios
if ($model->status === 0) { //if publish isn't set:
$model->setScenario('Insert');
} elseif ($model->status === 1){
$model->setScenario('Publish');
}
And on my model:
public function rules()
{
return array(
array('name, category', 'required', 'on'=>'Insert'),
array('name, category, image', 'required', 'on'=>'Publish'))
I got no validations displayed.
The edit is a total different question so I’m creating a new response
Before assigning the scenario, you need to fill your model with the post values
And then you can validate the datas with
Wich return true or false.
Or you can validate the datas while saving them:
It also return true or false