Yii-向导行为扩展-跳过步骤

Yii-向导行为扩展-跳过步骤,yii,wizard,yii-extensions,Yii,Wizard,Yii Extensions,我希望stackoverflow上的人对向导行为扩展有一定的经验: 问题是,当我在第一页(用户)上单击submit时,它会一直转到billing页面并跳过company页面…帮助 我有3个步骤来收集信息:用户、公司和账单页面。以下是控制器中的“我的行为”功能: public function behaviors() { return array( 'wizard'=>array( 'class'=>'ext.WizardBehavior.WizardBe

我希望stackoverflow上的人对向导行为扩展有一定的经验:

问题是,当我在第一页(用户)上单击submit时,它会一直转到billing页面并跳过company页面…帮助

我有3个步骤来收集信息:用户、公司和账单页面。以下是控制器中的“我的行为”功能:

public function behaviors() {
    return array(
     'wizard'=>array(
      'class'=>'ext.WizardBehavior.WizardBehavior',
      'steps'=>array(
       'user','company','billing'
      )
     )
    )
}
这是我的流程步骤功能:

public function wizardProcessStep($event) {
    $name = '_wizard'.ucfirst($event->step);
    if (method_exists($this, $name)) {
        call_user_func(array($this,$name), $event);
    } else {
        throw new CException(Yii::t('yii','{class} does not have a method named "{name}"', array('{class}'=>get_class($this), '{name}'=>$name)));
    }
}
以下是我的公司步骤作为示例:

protected function _wizardCompany($event) {
    echo 'called company';
    exit();
    $company=new Company;
    if(isset($_POST['Company'])) {
        $company->attributes=$_POST['Company'];
        if($company->validate()) {
            $event->sender->save($company->attributes);
            $event->handled = true;
        }
    }
    $this->render('new_company',array(
        'company'=>$company,
        'event'=>$event,
    ));
}

这似乎不是一个bug,但它是经过设计的。默认情况下,WizardBehavior会跳到第一个未处理的步骤

您可能正在测试向导,并在“用户”和“公司”中输入了一些内容。当您现在处于“计费”状态时,请返回“用户”(通过url或链接)。输入某个内容并再次提交,它将跳过计费,因为这是第一个未处理的步骤。请注意,您可以通过URL和链接转到“公司”和以前处理的所有步骤

可以通过将此行为设置为false

public function behaviors() {
    return array(
     'wizard'=>array(
      'autoAdvance' => false,
     )
    )
}

或者您实现onFinish事件,以便在测试时轻松重置向导。

您是否也可以发布您的_wizardUser($event)方法,该方法可能有一些设置下一步计费的代码。User中的代码与wizardCompany相同,只需将
Company
替换为
User
,将
$Company
替换为
$User
就可以了……我的行为功能中没有设置
'autoAdvance'=>false
,谢谢,成功了!