常规的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. windows系统npm如何升级自身

    其实使用npm升级各种插件是很方便的,比如我想升级express框架,使用如下命令 npm update express 如果你的express是全局安装,则 npm update -g expres ...

  2. Python之路第六天,基础(7)-正则表达式(re)

    Python RE模块(正则表达式) 就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现.正则表达式模式被编译成 ...

  3. Linux下MySQL安装及命令使用

    先rpm -qa mysql 查看是否安装 yum list |grep mysql 查看MySQL的一些包 yum install -y mysql-server mysql mysql-devel ...

  4. SSAS维度设计中CustomRollupColumn的用法-自定义聚合方式

          CustomRollupColumn说明:指定包含多维表达式的列,该表达式可用于聚合特性的度量值.这个属性覆盖给定度量值的AggregateFunction的属性. 解释:通常我们的度量值 ...

  5. ModelMap和ModelAndView(转)

    转自:http://bao1073740756-126-com.iteye.com/blog/1549597 首先介绍ModelMap和ModelAndView的作用 ModelMap ModelMa ...

  6. 32位程序调用Oracle11gR2数据库libclntsh.so失败

    [问题描述]32位程序调用Oracle11gR2数据库的libclntsh.so库时会返回失败. [问题原因]32位程序只能调用32位的Oracle客户端实例包,而R2数据库默认安装完毕后是没有lib ...

  7. listview加载网络图片

    ListView加载网络数据和图片 2013-09-25 00:08:10|  分类: 默认分类 |  标签:android  |举报|字号 订阅     如,从服务器端获得商品名称.价格.简介和图片 ...

  8. 为什么不能在scrollview中直接添加一个image,然后使animation.begin()??

    http://stackoverflow.com/questions/17267451/animation-cant-begin-in-scrollview-in-windows-phone 以上是我 ...

  9. How ASP.NET MVC Works?

    原文地址:http://www.cnblogs.com/artech/archive/2012/04/10/how-mvc-works.html?ADUIN=7783008&ADSESSION ...

  10. Linux开发环境配置

      配置JDK: tar -xzvf jdk-7u71-linux-x64.tar.gz rm -f jdk-7u71-linux-x64.tar.gz 测试:java -version 配置Grad ...