gpt4 book ai didi

yii CHtml::button 和 POST 请求到 Controller

转载 作者:行者123 更新时间:2023-12-04 14:05:25 27 4
gpt4 key购买 nike

有没有办法拥有CHtml::button向 Controller 发送 post 请求

<?php echo CHtml::button('Button Text', array('submit' => array('controller/action'))); ?>

我想复制 CHtml::link功能和 POST 到 Controller
<?php echo CHtml::link('Delete',"#", array("submit"=>array('delete', 'id'=>$data->ID), 'confirm' => 'Are you sure?')); ?>

编辑:

该按钮未提交表单

最佳答案

尝试这个:

echo CHtml::button('Delete',
array(
'submit'=>array('controllername/actionname',array('id'=>$id)),
'confirm' => 'Are you sure?'
// or you can use 'params'=>array('id'=>$id)
)
);

如您所见 button还走特价 htmlOptions属性 clientChange .

更新 submit的澄清,来自 doc link ():

submit: string, specifies the URL to submit to. If the current element has a parent form, that form will be submitted, and if 'submit' is non-empty its value will replace the form's URL. If there is no parent form the data listed in 'params' will be submitted instead (via POST method), to the URL in 'submit' or the currently requested URL if 'submit' is empty. Please note that if the 'csrf' setting is true, the CSRF token will be included in the params too.



强调我的

正如您提到要执行删除操作,默认的 gii 生成 actionDelete预计 id在 url 中,因此我在 url 中传递了 id,即 submit选项。

关于yii CHtml::button 和 POST 请求到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14189872/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com