常规的delete方法如下:

/** 
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'index' page.
*/
public function actionDelete()

if(Yii::app()->request->isPostRequest)

// we only allow deletion via POST request
$this->loadModel()->delete();

// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(array('index'));

else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}


转载请注明:PHP攻城师

http://blog.csdn.net/phpgcs/article/details/10393305


通过POST请求来删除,会弹出对话框,让用户确认,更安全些。

在CGridView 中 ,会自动的发送POST 请求。

122 array(
123 'headerHtmlOptions'=>array('width'=>'60px'),
124 'class'=>'CButtonColumn', 'header'=>'操作',
125 'template'=>'{view} {update} {delete}',
126 'buttons'=>array(
127 'view'=>array(
128 'label'=>'查看',
129 'url'=>'Yii::app()->createURL("supervise/default/view", array("id"=>$data->id))',
130 'imageUrl'=>Yii::app()->baseUrl.'/images/icons/user.png',
131 ),
132 'update'=>array(
133 'label'=>'修改',
134 'url'=>'Yii::app()->createURL("supervise/default/update", array("id"=>$data->id))',
135 'imageUrl'=>Yii::app()->baseUrl.'/images/icons/user_edit.png',
136 ),
137 'delete'=>array(
138 'label'=>'删除',
139 'url'=>'Yii::app()->createURL("supervise/default/delete", array("id"=>$data->id))',
140 'imageUrl'=>Yii::app()->baseUrl.'/images/icons/user_delete.png',
141 ),
142 ),
143 ),

但是如果在别的地方你简单的使用 createUrl来创建的都是GET REQUEST,无法删除记录的

Error 400

Invalid request. Please do not repeat this request again.

解决方法:

16 <?php
17 echo CHtml::link(CHtml::encode('删除巡察记录'), array('/***/default/delete', 'id'=>$id),
18 array(
19 'submit'=>array('/***/default/delete', 'id'=>$id),
20 'class' => 'delete','confirm'=>'This will remove the image. Are you sure?'
21 )
22 );
23 ?>

转载请注明:PHP攻城师

http://blog.csdn.net/phpgcs/article/details/10393305






yii post delete request more safe的更多相关文章

  1. A crawler that sent a DELETE request to every resource it encountered

    RESTful Web APIs_2013 The crawler simulates a very curious but not very picky human. Give it a URL t ...

  2. Spring REST for DELETE Request Method Not Supoorted

    http://stackoverflow.com/questions/22055251/sending-data-with-angularjs-http-delete-request I have a ...

  3. ASP.NET MVC got 405 error on HTTP DELETE request

    使用Backload的时候在本地调试通过,上传服务器后出现405错误(监控通信时可以发现ajax的返回结果为405) 通过修改webconfig可以解决: <system.webServer&g ...

  4. 405 Method Not Allowed error with PUT or DELETE Request on IIS Server

    昨天手贱去一台服务器上装了Webdav. 一开始以为这个报错是跨域问题, 最近一直遇到用自动的publish发布到FTP出问题也就没想到是Webdav的问题 而且这东西装了还不能删除 处理办法 IIS ...

  5. 通过 Spring RestTemplate 调用带请求体的 Delete 方法(Delete With Request Body)

    Spring 框架的RestTemplate 类定义了一些我们在通过 java 代码调用 Rest 服务时经常需要用到的方法,使得我们通过 java 调用 rest 服务时更加方便.简单.但是 Res ...

  6. HTTP Request GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE Methods

    注:本文为个人学习摘录,原文地址为:http://javaeedevelop.iteye.com/blog/1725299 An HTTP request is a class consisting ...

  7. request有get,post,put,delete等方法大全

    注:本文为个人学习摘录,原文地址为:http://javaeedevelop.iteye.com/blog/1725299 An HTTP request is a class consisting ...

  8. python 视图 (FBV、CBV ) 、Request 和Response对象 、路由系统

    一.FBV和CBV1.基于函数的view,就叫FBV(Function Based View) 示例: def add_book(request): pub_obj=models.Publisher. ...

  9. SQL SERVER 2005删除维护作业报错:The DELETE statement conflicted with the REFERENCE constraint "FK_subplan_job_id"

    案例环境: 数据库版本: Microsoft SQL Server 2005 (Microsoft SQL Server 2005 - 9.00.5000.00 (X64) ) 案例介绍: 对一个数据 ...

随机推荐

  1. php.ini 全站,和htaccess web目录 默认头部和尾部 auto_prepend_file

    php.ini ; Automatically add files before PHP document. ; http://php.net/auto-prepend-file auto_prepe ...

  2. 混合使用Azure LB和ILB访问相同web服务(2)

    那么现在开始,我们配置下两台WEB服务器的Internal Load  balancer: 打开Powershell,检查当前两台虚拟机的端点配置: Get-AzureVM  -ServiceName ...

  3. 关于KeyEvent.Callback

    keycode------------>KEYCODE_BACK,KEYCODE_MENU event.getAction------->ACTION_DOWN,ACTION_UP,ACT ...

  4. 去掉ExpandableListView的箭头图标

    到ExpandableListView时有个箭头图标系统自带的在你自定义布局也不能去掉只要设置一个属性即可,如下: settingLists.setGroupIndicator(null);  ~~~ ...

  5. 简单方便又实用的在线作图工具:ProcessOn

    说到Visio大家都不陌生,虽然没有Word那么火,但很多业内朋友都在用,一用就是好多年,Visio是相对比较传统和专业的工具,新手在没人指导的情况下一般很难上手,下载和安装以及“授权”都是个问题,很 ...

  6. C++14介绍

    C++14标准是 ISO/IEC 14882:2014 Information technology -- Programming languages -- C++ 的简称[1]  .在标准正式通过之 ...

  7. (四)boost库之正则表达式regex

    (四)boost库之正则表达式regex 正则表达式可以为我们带来极大的方便,有了它,再也不用为此烦恼 头文件: #include <boost/regex.hpp> 1.完全匹配 std ...

  8. JAVA反射学习网摘

    程序运行时,允许改变程序结构或变量类型,这种语言称为动态语言".从这个观点看,Perl,Python,Ruby是动态语言,C++,Java,C#不是动态语言.但是JAVA有着一个非常突出的动 ...

  9. 【二叉树->链表】二叉树结构转双向线性链表结构(先序遍历)

    二叉树存储结构属于非线性链表结构,转化成线性链表结构,能简化操作和理解.然而由非线性转线性需要对整个树遍历一次,不同的遍历方式转化结果页不一样.下面以先序为例. 方法一: 递归法.递归遍历二叉树,因为 ...

  10. sigaction函数解析

    http://blog.chinaunix.net/uid-1877180-id-3011232.html sigaction函数解析  sigaction函数的功能是检查或修改与指定信号相关联的处理 ...