renathy
(Renate Vidruska)
September 15, 2011, 10:04am
1
Hi!
I am using wizard-behavior extension, but I do not understand how to swith to CActiveRecord.
Tutorial says something like this:
$model = new Address();
$model->attributes = $event->data;
$form = $model->getForm();
if (($form->submitted() || $form->submitted('save_draft')) && $form->validate()) {
$event->sender->save($model->attributes);
$event->handled = true;
}
But I do not have "$form = $model->getForm();" as I am using activerecord instead. I am creating my form in the following way:
<?php $form = $this->beginWidget('GxActiveForm', array(
'id' => 'address-form',
'enableAjaxValidation' => true, //GxActiveForm extends CActiveForm
));
?>
<?php echo $form->textField($model, 'street', array('maxlength' => 128)); ?>
...
[/code]
jacmoe
(Jacob Moen)
September 15, 2011, 10:08am
2
FormModel doesn’t have that function either.
It’s a feature of the models used by the wizard.
Don’t use active forms, just create and update the db models in your wizard form model.
renathy
(Renate Vidruska)
September 15, 2011, 11:16am
3
As I am new to YII, could please give me an example how my processStep should look like:
[code]
$model = new Address(); //model is address - street, city etc.
$model->attributes = $event->data;
…
// how to check here if form is submitted and if submitted then:
if (submitted) ?
{
$event->sender->save($model->attributes);
$event->handled = true;
}
…
$this->render(‘wizardForm’,
array( 'event'=>$event
, 'model'=>$model
));
Yeti
(Chris)
September 15, 2011, 11:43am
4
The processStep handler generally looks like an action would do for a single form, except it usually doesn’t save anything to the model; that’s usually done in the finished handler.
Take a look at the manual (PDF Manual) which contains code snippets, and/or download the demo (ZIP file) and take a look.
BTW, I write a getForm() method for my models that returns the form for that model - change the “$form = $model->getForm();” to the way you choose to get your form instance; after that it’s just a form.
renathy
(Renate Vidruska)
September 15, 2011, 4:49pm
5
Actually I understand everything about wizard,
I do not understand how to getform of model in my case.
Before I used if (isset($_POST[‘Address’]) to check if form was posted, but this do not work for this case.
I need to get form (as mentioned in post above - writing getForm) that was posted, do not no how to get it.
rmandovnz
(Rmandovnz)
January 7, 2012, 6:40am
6
Hello there renathy…
Im start using the wizad behavior ext, and i need to ask…
Can you figure it out how to use it with activerecord?
Do i have to write on AR’s models the getForm method?
Also ask you if the aproach publish in this topic (http://www.yiiframework.com/forum/index.php?/topic/16471-wizard-behavior/page__st__20 ) nro.22 works for you?
Thankyou…