2012-07-18 52 views
0

我正在使用ATK4 4.1.1並在頁面中添加了一個按鈕。我希望這個按鈕在按下時觸發數據庫表的更新,所以在頁面中創建了類似這樣的代碼。如何讓按鈕觸發ATK4中的數據庫更新?

$f=$p->add('Form',null,null,array('form_empty'))->setFormClass('horizontal bottom-padded'); 

    $b1=$f->add('Button')->set('Finished'); 
    $b1->js("click")->univ()->ajaxec($this->api->url(null, array("s"=>"D"))); 

    $b1->js('click', $b1->js()->load(
     $this->api->url(null,array('s'=>'D')) 
    )); 

    .. .. .. .. 

    if (isset($_GET['s'])) {    
     $ss=$this->add('Model_SprintStatus') 
       ->loadBy(array('member_id'=>$p->api->auth->get('id'))); 
     $new_status=$_GET['s']; 
     $ss->set('status',$new_status); 
     $ss->update(); 
    } 

當我訪問該頁面時,它顯示正常,但單擊按鈕時,我得到一個錯誤說的方法

BaseException 

Method is not defined for this object 

Additional information: 

method: url 
arguments: Array ([0] => [1] => Array ([s] => D) 

我用從重裝以下agiletoolkit.org部分稱爲解剖爲例。當我得到這個錯誤時,我採用了這個例子,並使用與例子相同的代碼創建了一個新頁面,我也從該頁面獲得了類似的錯誤。

BaseException 

    Method is not defined for this object 

    Additional information: 

    method: url 
    arguments: Array ([0] => [1] => Array ([side] => 1 [myajax] => 1)) 

除了嘗試上述ajaxec行,我也試過以下

$b1->js('click', $b1->js()->load($this->api->url(null,array('s'=>'D')))); 

$b1->js('click', $b1->js()->atk4_load($this->api->url(null,array('s'=>'D')))); 

但他們也回來與相同的錯誤。

也許我錯過了一些東西,或者它可能是ATK4 4.1.1和4.2之間的一個變化,但是我現在不能升級,因爲我試圖滿足最後期限,所以我必須執行什麼方法從按鈕此更新的ATK點擊4.1.1

感謝

回答

1

還有一個更簡單的方法:

if($this->add('Button')->setLabel('Clickme')->isClicked()){ 

     // .... 

     $this->js()->univ()->successMessage('Updated') 
      ->page($this->api->getDestinationURL())->execute(); 

} 

這只是簡要記錄http://agiletoolkit.org/whatsnew/may2011

+0

你能確認addButton的語法嗎?在4.1上,我收到一個錯誤,說沒有爲此對象addButton定義方法。 – 2012-08-04 18:11:47

+0

確定 - 制定了正確的語法添加按鈕,並修改了上述內容,但現在得到一個Ajax錯誤,當按下按鈕時沒有任何信息爲什麼 - 任何建議? POST URL是http://team.pscrum/?page = tktdetail&paperless_tktdetail_button =點擊 – 2012-08-04 18:23:44

0

答案是...

// create a form to put the button in with minimal styling 
    $f=$p->add('Form',null,null,array('form_empty'))->setFormClass('horizontal bottom-padded'); 

    // Add the button with a confirm request and do an ajax call 
    // passing a new GET parameter called state 
    $f->add('Button')->set('Update') 
     ->js('click')->univ()->confirm('Confirm ?') 
     ->ajaxec($this->api->getDestinationURL(null,array('state'=>'D'))); 

    // If the parameter is set, this is executed by the ajax callback 
    if (isset($_GET['state'])) {    
     //add the model (change name to yours) 
     // You can either use load($id) if you already have the primary key 
     // or an array of fields and use loadBy to get the records to be updated 
     $ss=$this->add('Model_SprintStatus')->loadBy(array(
       'member_id'=>$p->api->auth->get('id') 
       ) 
      ); 

      // set some variables to hold the old status from the model 
      // and the new one which was in the GET parameter we passed 
      $old_status=$ss->get('status'); 
      $new_status=$_GET['state']; 

      // Set the status column to the new value and execute the update 
      $ss->set('status',$new_status); 
      $ss->update(); 

      // and provide some feedback to the user that it worked ! 
      $this->js()->univ()->successMessage('Updated') 
       ->page($this->api->getDestinationURL())->execute(); 
    } 

如果你不希望用戶的任何反饋,你可以省略 - >按鈕定義上的confirm()和包含successMessag的整行e和想必你也可以通過改變它改變按鈕的狀態是的,如果(isset內部類($ _ GET ...

相關問題