yii?rules()

WBOY
Release: 2016-06-20 12:52:58
Original
1086 people have browsed it

public function rules()	{		return array(			array('display, title', 'required'),			array('title', 'length', 'max'=>300),            array('id, display, date, title', 'safe'),---(1)			array('id, display, date, title', 'safe', 'on'=>'search'),---(2)		);	}
Copy after login

(1)和(2)的作用是什么?


回复讨论(解决方案)

http://www.yiichina.com/doc/guide/1.1/form.model
看看文档吧,说不清楚...

safe 安全的

array('id, display, date, title', 'safe')
表示 id, display, date, title 可安全的使用,即不需要检验

array('id, display, date, title', 'safe', 'on'=>'search')
中的 'on'=>'search' 表示本条规则适用于 search 模块

其实这个思维方法与我们的有很大的不同
他先假定所有的传入数据都需要验证,然后在规则中开列可以跳过验证的字段

而我们一般这样做:假定所有传入的数据都是安全的,然后开列出需要检查的字段

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template