I have been programming with Yii for a couple of weeks, have had success customizing for my look and feel, and also have customized the login form to match my requirements.
Now I’m about to do the User Registration part.
I’m new to MVC and Yii, so sometimes I get lost.
I would like to have 3 views, like three wizard pages, for different parts of the registration, like username, password, then personal information, then hobbies, each one in a new wizard page. I will have a user table and a userProfile table. This should go each to two models, shouldn’t it?
So, I don’t know how to split one view to handle this scenario.
Any opinion is valid! I can change the structure if needed and if it’s reasonable.
For DB tables i use an AR model and for forms i use a CForm Model. I would go a head and use two AR tables for the two tables and a single RegistrationForm that handles three actions(?) as you described for the three different registration processes. You could use CJuiTabs to do the three stages split.
I want to share my approach to create a multi-page form. Please tell me if its so ok or i am complicating it.
I have in my Controller the function actionCreate:
if(isset($_POST['form']))
{
if ($_POST[1]) {
$_SESSION['form'][2] = $_POST['form'];
if ($_SESSION['form'][1]) {
foreach ($_SESSION['form'][1] as $key=>$value){
$model->$key=$value;
}
}
}elseif($_POST[2]){
$_SESSION['form'][1] = $_POST['form'];
} // endif
$model->attributes=$_POST['form'];
In the _form.php View i have an CActiveForm widget with Buttons named 1 and 2, so when i am on the first page i click the button 2 to display the second page and save the posted variables in my session.
When i want to go back to the first page i click on the Back-Button -> 1 and the values from the session are populated back to my form with the foreach loop.
You can write all the form in one html page, and create some <div> in wich to put your wizard’s page.
The button next-back are simple javascript button that plays a bit with visibility of panels.
Using this apporoach you can leave the action in the controller as it is, because you have at any post all the input (and so you don’t have to dirty on $_SESSION), and is even a bit (but just a bit) more efficient, because you avoid some posts.
If the wizard is "static" (if the nexts pages are not depending from data inserted in the previous), that can be a solution.