Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example image for Github page #3

Open
drsdre opened this issue Jan 17, 2016 · 6 comments
Open

Example image for Github page #3

drsdre opened this issue Jan 17, 2016 · 6 comments

Comments

@drsdre
Copy link
Owner

drsdre commented Jan 17, 2016

screen shot 2016-01-17 at 13 57 42

@FernandoMauricio
Copy link

Hi drsdre, you could make an example to model? Congrats to advanced....

@elshazer
Copy link

hello, i need a example of wizardwidget with steps that contains registration form in Yii-php

@drsdre
Copy link
Owner Author

drsdre commented Jun 16, 2016

Here is some basic example code. I've left out the actual views of the step as this is up to how your model is created.

    /**
     * Wizard controller action example.
     *
     * @param null $step
     *
     * @return mixed
     */
    public function actionIndex($id, $step = null)
    {
        $request = Yii::$app->request;

        // Lookup dataset model or start new one
        if (! $Model = Model::findOne([$id])) {
            $Model = new Model();
        }

        // Process a model save
        if ($Model->load($request->post())) {
            if ( $Dataset->save() ) {
                if ($request->post('step') == 'save-final') {
                    // Final wizard step, go to overview
                    $this->redirect( [ '/overview/index',  ] );
                } else {
                    // Refresh widget with the saved model and continue with step 3
                    $this->redirect( [ 'index', 'model' => $Model, 'step' => 3 ] );
                }
            }
        }

        return $this->render('index', [
            'model' => $Model,
            'step' => $step,
        ]);
    }
<?php
// Wizard view example

use yii\web\View;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use drsdre\wizardwidget\WizardWidget;

/* @var $this yii\web\View */
/* @var $Model common\models\Model */
/* @var $step integer */
/* @var $form yii\widgets\ActiveForm */

$this->title = Yii::t('app', 'Example Form Wizard');

$form = ActiveForm::begin();

$wizard_config = [
    'steps' => [
        '1' => [
            'title' => 'Step 1',
            'icon' => 'glyphicon glyphicon-cloud-download',
            'content' => $this->render('_step1', ['form' => $form, 'Model' => $Model]),
            'buttons' => [
                'next' => [
                    'title' => 'Next: Step 2',
                    'options' => ['class'=> 'btn btn-success']
                ]
            ],
        ],
        '2' => [
            'title' => 'Step 2',
            'icon' => 'glyphicon glyphicon-cloud-upload',
            'content' => $this->render('_step2', ['form' => $form, 'Model' => $Model]),
            'buttons' => [
            'buttons' => [
                'next' => [
                    'title' => 'Next: Final Step 3',
                    'options' => ['class'=> 'btn btn-success']
                ]
            ],
        ],
        '3' => [
            'title' => 'Step 3 - Final',
            'icon' => 'glyphicon glyphicon-ok',
            'content' => $this->render('_step3', ['form' => $form, 'Dataset' => $Dataset]),
            'buttons' => [
                'save' => [
                    'html' => Html::submitButton(
                        Yii::t('app', 'Load data'),
                        [
                            'class' => 'btn btn-success',
                            'id' => 'wizard_step3_final',
                            'name' => 'step',
                            'value' => 'save-final'
                        ]
                    ),
                ],
            ],
        ],
    ],
    'start_step' => $step,
];

echo WizardWidget::widget($wizard_config);

ActiveForm::end();

@elshazer
Copy link

Thank you :D :)

2016-06-16 3:35 GMT-06:00 AFS [email protected]:

Here is some basic example code. I've left out the actual views of the
step. This is up to how your model is setup.

/**
 * Wizard controller action example.
 *
 * @param null $step
 *
 * @return mixed
 */
public function actionIndex($id, $step = null)
{
    $request = Yii::$app->request;

    // Lookup dataset model or start new one
    if (! $Model = Model::findOne([$id])) {
        $Model = new Model();
    }

    // Process a model save
    if ($Model->load($request->post())) {
        if ( $Dataset->save() ) {
            if ($request->post('step') == 'save-final') {
                // Final wizard step, go to overview
                $this->redirect( [ '/overview/index',  ] );
            } else {
                // Refresh widget with the saved model and continue with step 3
                $this->redirect( [ 'index', 'model' => $Model, 'step' => 3 ] );
            }
        }
    }

    return $this->render('index', [
        'model' => $Model,
        'step' => $step,
    ]);
}
title = Yii::t('app', 'Example Form Wizard'); $form = ActiveForm::begin(); $wizard_config = [ 'steps' => [ '1' => [ 'title' => 'Step 1', 'icon' => 'glyphicon glyphicon-cloud-download', 'content' => $this->render('_step1', ['form' => $form, 'Model' => $Model]), 'buttons' => [ 'next' => [ 'title' => 'Next: Step 2', 'options' => ['class'=> 'btn btn-success'] ] ], ], '2' => [ 'title' => 'Step 2', 'icon' => 'glyphicon glyphicon-cloud-upload', 'content' => $this->render('_step2', ['form' => $form, 'Model' => $Model]), 'buttons' => [ 'buttons' => [ 'next' => [ 'title' => 'Next: Final Step 3', 'options' => ['class'=> 'btn btn-success'] ] ], ], '3' => [ 'title' => 'Step 3 - Final', 'icon' => 'glyphicon glyphicon-ok', 'content' => $this->render('_step3', ['form' => $form, 'Dataset' => $Dataset]), 'buttons' => [ 'save' => [ 'html' => Html::submitButton( Yii::t('app', 'Load data'), [ 'class' => 'btn btn-success', 'id' => 'wizard_step3_final', 'name' => 'step', 'value' => 'save-final' ] ), ], ], ], ], 'start_step' => $step, ]; echo WizardWidget::widget($wizard_config); ActiveForm::end(); — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com//issues/3#issuecomment-226436464, or mute the thread https://github.com/notifications/unsubscribe/AQZvvJytDqLO3PDGf-t9CnkvMTorCXDKks5qMRj7gaJpZM4HGd_k .

@earome
Copy link

earome commented Nov 18, 2016

Hi drsdre, excellent code. I am trying to use it but I am getting errors, can you please post the complete code indicating where to place which code. Thanks in advance

@jstudioo
Copy link

hi @drsdre your example code
'content' => $this->render('_step3', ['form' => $form, 'Dataset' => $Dataset]),
should be
'content' => $this->render('_step3', ['form' => $form, 'Model' => $Model]),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants