我正在使用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中的按钮点击更新
由于
答案 0 :(得分:1)
有一种更简单的方法:
if($this->add('Button')->setLabel('Clickme')->isClicked()){
// ....
$this->js()->univ()->successMessage('Updated')
->page($this->api->getDestinationURL())->execute();
}
中简要记录的
答案 1 :(得分: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 ......