Questionaire With Several Steps

I have a questionaire where the user has to go 4 steps.

MySQL-table: questionaire

fields

question1, char(80)

reply1, char(80)

question2, char(80)

reply2, char(80)

question3, char(80)

reply3, char(80)

question4, char(80)

reply4, char(80)

First view:

show question 1+2

-> answer question 1+2 -> save -> save answer 1+2 in table "questionaire"

Second view:

show question 1+2 with the answers 1+2 and ask question 3+4

-> answer question 3+4 -> save -> save answer 3+4 in table "questionaire"

Third view:

show question und replies 1-4 again to correct possible mistakes -> then save …

Forth view:

show again all questions and replies, not editable

????????????

My question:

????????????

I don’t want to use 4 actions in the questionaireController

and also not 4 views.

I only want tho use 1 controller and 1 view.

What the right Yii-way for doing this?

Modules, Components, Widgets, or what?

I wish all a Happy New Year

… it would be nice to get first answers this year, 2013 :slight_smile:

Jannis

PS.: I don’t want to use javascript/ajay (I am not used with them). I want to save the answers as soon as possible in the MySQL-table.

Yes, of course, in reality I have two relational tables:

questions : answer (1:n) - but I wanted to make my example easy.

Who can give me some hints, which Yii-way I should take?

I have learned Yii 2 weeks ago - and reading the Yii-book of Ullman, I understood a lot but not all.

In order to avoid multiple, redundant actions in controller you can use scenarios (in your controller), when initalizing AR in each step (i.e. $model=MyARecord("step1"); ). Using scenarios also enable you to get rid off mutiple view-files (i.e. view_step1.php, …_step2.php) by detecting used scenario in view and structuring it for example with a switch construct (based on detected scenario) .

This certainly would be "a yii-way to do it", nevertheless there are others…

one more hint: current/previous scenario ("step") you can transport between your requests in form of a hidden field and validation rules can be defined dedicated to each scenario by using the "on" operator

Check out the wizard-behavior extension. It might be what you need and the manual is very clear.