【发布时间】:2012-04-17 11:13:49
【问题描述】:
我是车轮新手(我相信我会在这里发很多帖子)所以请耐心等待。
我在“用户”的控制器下有“注册”和“登录”两种形式。所以我的网址是这样的。
/用户/注册/ /用户/登录/
目前在我的模型文件夹中,我只是在 init 方法中使用 user.cfc 验证“注册”页面 - 这很好用。
所以本质上......我的问题是......关于我的登录表单的验证;我是否必须始终将验证放入 init 方法或其他方法中?如果是这样,我该怎么做?当然,每种形式都有不同的字段......所以我需要知道一些关于检测当前正在播放的形式的逻辑。
希望这是有道理的。作为参考,我的 user.cfc 模型目前如下所示:
<cfcomponent extends="Model" output="true">
<cffunction name="init">
<cfset validate( property='userName', method='validateAlphaNumeric') />
<cfset validatesPresenceOf( properties='userName') />
<cfset validatesUniquenessOf( properties='userName') />
<cfset validatesFormatOf( property='userEmail', type='email', message="Email address is not in a valid format.") />
<cfset validatesPresenceOf( properties='userEmail') />
<cfset validatesUniquenessOf( properties='userEmail') />
<cfset validatesPresenceOf( properties='userPassword') />
<cfset validatesConfirmationOf( property='userPassword') />
<cfset validatesLengthOf( property="userToken", allowBlank=true) />
</cffunction>
<cffunction name="validateAlphaNumeric" access="private">
<cfif REFind("[^A-Za-z0-9]", this.userName, 1)>
<cfset addError( property="userName", message="User name can only contain letters and numbers." ) />
</cfif>
</cffunction>
</cfcomponent>
谢谢, 迈克尔。
【问题讨论】:
-
在您的第一个验证规则中,您不需要
property='userName'。它唯一需要的是method参数。
标签: model-view-controller coldfusion railo cfwheels