system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.i18n system.i18n.gettext system.logging system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers

CCaptchaAction

system.web.widgets.captcha
继承 class CCaptchaAction » CAction » CComponent
实现 IAction
可用自 1.0
版本 $Id$
CCaptchaAction renders a CAPTCHA image.

CCaptchaAction is used together with CCaptcha and CCaptchaValidator to provide the CAPTCHA feature.

You must configure properties of CCaptchaAction to customize the appearance of the generated image.

Note, CCaptchaAction requires PHP GD2 extension.

Using CAPTCHA involves the following steps:
  1. Override CController::actions() and register an action of class CCaptchaAction with ID 'captcha'.
  2. In the form model, declare an attribute to store user-entered verification code, and declare the attribute to be validated by the 'captcha' validator.
  3. In the controller view, insert a CCaptcha widget in the form.

公共属性

隐藏继承的属性

属性类型描述被定义在
backColor integer the background color. CCaptchaAction
controller CController the controller who owns this action. CAction
fontFile string the TrueType font file. CCaptchaAction
foreColor integer the font color. CCaptchaAction
height integer the height of the generated CAPTCHA image. CCaptchaAction
id string id of this action CAction
maxLength integer the maximum length for randomly generated word. CCaptchaAction
minLength integer the minimum length for randomly generated word. CCaptchaAction
padding integer padding around the text. CCaptchaAction
testLimit integer how many times should the same CAPTCHA be displayed. CCaptchaAction
transparent boolean whether to use transparent background. CCaptchaAction
verifyCode string Gets the verification code. CCaptchaAction
width integer the width of the generated CAPTCHA image. CCaptchaAction

受保护的属性

隐藏继承的属性

属性类型描述被定义在
sessionKey string Returns the session variable name used to store verification code. CCaptchaAction

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CAction
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
getController() CAction
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getId() CAction
getVerifyCode() Gets the verification code. CCaptchaAction
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
raiseEvent() Raises an event. CComponent
run() Runs the action. CCaptchaAction
validate() Validates the input to see if it matches the generated code. CCaptchaAction

受保护的方法

隐藏继承的方法

方法描述被定义在
generateVerifyCode() Generates a new verification code. CCaptchaAction
getSessionKey() Returns the session variable name used to store verification code. CCaptchaAction
renderImage() Renders the CAPTCHA image based on the code. CCaptchaAction

属性详情

backColor 属性
public integer $backColor;

the background color. For example, 0x55FF00. Defaults to 0xFFFFFF, meaning white color.

fontFile 属性
public string $fontFile;

the TrueType font file. Defaults to Duality.ttf which is provided with the Yii release.

foreColor 属性
public integer $foreColor;

the font color. For example, 0x55FF00. Defaults to 0x2040A0 (blue color).

height 属性
public integer $height;

the height of the generated CAPTCHA image. Defaults to 50.

maxLength 属性
public integer $maxLength;

the maximum length for randomly generated word. Defaults to 7.

minLength 属性
public integer $minLength;

the minimum length for randomly generated word. Defaults to 6.

padding 属性
public integer $padding;

padding around the text. Defaults to 2.

sessionKey 属性 只读
protected string getSessionKey()

Returns the session variable name used to store verification code.

testLimit 属性
public integer $testLimit;

how many times should the same CAPTCHA be displayed. Defaults to 3.

transparent 属性 (自版本 v1.0.10 可用)
public boolean $transparent;

whether to use transparent background. Defaults to false.

verifyCode 属性 只读
public string getVerifyCode(string $regenerate=false)

Gets the verification code.

width 属性
public integer $width;

the width of the generated CAPTCHA image. Defaults to 120.

方法详情

generateVerifyCode() 方法
protected string generateVerifyCode()
{return} string the generated verification code

Generates a new verification code.

getSessionKey() 方法
protected string getSessionKey()
{return} string the session variable name

Returns the session variable name used to store verification code.

getVerifyCode() 方法
public string getVerifyCode(string $regenerate=false)
$regenerate string whether the verification code should be regenerated.
{return} string the verification code.

Gets the verification code.

renderImage() 方法
protected string renderImage(string $code)
$code string the verification code
{return} string image content

Renders the CAPTCHA image based on the code.

run() 方法
public void run()

Runs the action. If the GET parameter wsdlVar exists, the action will serve WSDL content; If not, the action will handle the remote method invocation.

validate() 方法
public whether validate(string $input, boolean $caseSensitive)
$input string user input
$caseSensitive boolean whether the comparison should be case-sensitive
{return} whether the input is valid

Validates the input to see if it matches the generated code.