yii2 提示Module not inserted due to validation error.
来源:互联网 发布:d3.js官网下载 编辑:程序博客网 时间:2024/04/30 11:34
项目的后台更改和添加文章突然无效了,查看系统日志发现是
Module not inserted due to validation error.
其实原因很简单,在表单中加入了百度编辑器,在给编辑器命名的时候使用了name="content",由于yii2 view页面在提交表单后,控制器要使用$model->load()来检查当前类名数组是否存在。
如:
view里的表单元素提交的值都放在Article[]数组中,提交的时候会产生这样的一个数组
array (size=2) '_csrf' => string 'cUI2b280TUciBGctXXAHLUUmdwMaBSsRIzIAORd8HDQYNQ8YB38JLg==' (length=56) 'Article' => array (size=6) 'title' => string '这是一篇测试文章' (length=24) 'add_time' => string '2015-10-15 08:39:43' (length=19) 'author' => string 'qmsu' (length=4) 'type_id' => string '1' (length=1) 'status' => string '0' (length=1) 'content' => string '<p>var_dump($post);</p>' (length=23)
如果在该数组外还存在其他的值,则$model->load()会返回false,从而无法添加或更新数据
eg:在Article数组外还有另外一个数据content,从而无法添加或更新数据
array (size=2) '_csrf' => string 'cUI2b280TUciBGctXXAHLUUmdwMaBSsRIzIAORd8HDQYNQ8YB38JLg==' (length=56) 'Article' => array (size=6) 'title' => string '这是一篇测试文章' (length=24) 'add_time' => string '2015-10-15 08:39:43' (length=19) 'author' => string 'qmsu' (length=4) 'type_id' => string '1' (length=1) 'status' => string '0' (length=1) 'content' => string '<p>var_dump($post);</p>' (length=23)
所以在view页面给表单元素命名时,应该使用如下方式name="Article[content]"
<input type="text" maxlength="255" value="" name="Article[content]" class="form-control" id="article-author">
注意:如果使用yii2自动生成表单则无需担心此问题
0 0
- yii2 提示Module not inserted due to validation error.
- HTTP Error 401.2 - You are not authorized to view this page due to invalid authentication headers
- Could not connect to ASM due to following error ORA-01031:insufficient privileges
- Eclipse 警告提示:Access restriction:The type JPEGCodec is not accessible due to...
- Eclipse 警告提示:Access restriction:The type JPEGCodec is not accessible due to restriction on
- ArcServer10 安装中提示The following features cannot not be installed due to missing prerequisites"
- Error 1069: The service did not start due to a logon failure
- 'Operation is not valid due to the current state of the object' error during postback
- [转]error - Operation is not valid due to the current state of the object.
- Agile Plm Notifications Are Not Being Sent Due to Node 0 Error
- Could not allocate CursorWindow size due to error -12 错误解决方法
- Could not allocate CursorWindow size due to error -12 错误解决方法
- Could not validate ASMSNMP password due to following error- "ORA-01031: insufficient privileges"
- Could not allocate CursorWindow size due to error -12 错误解决方法
- Could not allocate CursorWindow size due to error -12 错误解决方法
- JAVA ERROR---Access restriction: The type JOptionPane is not accessible due to restriction on requir
- [已解决]Could not allocate CursorWindow '' of size of size 2097152 due to error -12.
- CursorWindow: Could not allocate CursorWindow '......'of size 2097152 due to error -12.
- C++ 静态局部变量用法详解
- Linux LVM硬盘管理及LVM扩容
- UICollectionView请求网络数据显示(Text)
- 关于SandBox机制及文件读写的几种方式
- hdu 2011
- yii2 提示Module not inserted due to validation error.
- 实战分析一个崩溃的bug (2010-10-25 01:51:24)
- POJ 2718Smallest Difference(DFS)
- mybatis在xml文件中处理大于号小于号的方法
- 按钮背景图片 大小 和 位置 设置。
- 全局404定义
- Linux的用户和用户组管理
- spring aop的案例(一)日志拦截
- 洛谷P1012 拼数