2012-07-20 66 views
2

我希望有人在計算器有嚮導行爲擴展一些經驗:http://www.yiiframework.com/extension/wizard-behavior/的Yii - 嚮導行爲擴展 - 跳過步驟

的問題是,當我點擊提交的第一頁(用戶)上,這是不言而喻的所有到結算頁面的方式並跳過公司頁面...幫助?

我有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, 
    )); 
} 
+0

您是否可以發佈您的_wizardUser($ event)方法,該方法可能有一些代碼設置下一步計費。 – SuVeRa 2012-09-10 14:19:55

+0

User中的代碼與wizardCompany相同,只需用'user'和'$ company'替換'Company'和'$ user' – ews2001 2012-09-10 19:54:32

回答

1

這不似乎是一個錯誤,但通過設計。默認情況下,WizardBehavior跳到第一個未處理的步驟。

您可能正在測試您的嚮導,並在「用戶」和「公司」中輸入了一些內容。當您現在處於「帳單」狀態時,請返回「用戶」(通過網址或鏈接)。輸入一些內容並再次提交,它會跳到帳單,因爲這是第一個未處理的步驟。請注意,您可以通過網址和鏈接訪問「公司」以及以前處理的所有步驟。

這種行爲可以通過

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

被設置爲false,或者你實現onFinish事件,讓嚮導時,測試輕鬆重置。

+0

你去了哪裏......我沒有''autoAdvance'=> false'設置在我的行爲功能......謝謝,這是做到了! – ews2001 2012-09-21 17:12:10