0

我正在使用 ATK4 4.1.1 并向页面添加了一个按钮。我希望此按钮在按下时触发对数据库表的更新,因此在页面中创建了这样的代码。

    $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 中单击按钮

谢谢

4

2 回答 2

1

有一个更简单的方法:

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

      // ....

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

}

这仅在http://agiletoolkit.org/whatsnew/may2011中简要记录

于 2012-07-23T11:31:52.560 回答
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() 以及包含 successMessage 的整行,大概您还可以通过更改 if (isset( $_GET...

于 2012-07-19T17:40:15.267 回答