2012-07-18 135 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 ...