|

- 帖子
- 138
- 精华
- 0
- 积分
- 109
- 专家分
- 8 EXP
- 来自
- 陕西商洛
- 注册时间
- 2010-7-9
|
1#
发表于 2010-7-10 09:56
| 只看该作者
第一步:/**
* 默认控制器
*/
class Controller_Default extends Controller_Abstract
{
function actionImgcode()
{
// 在控制器中用下列代码返回一个图像验证码
return Helper_ImgCode::create(6, 900, 'simple');
}
}
第二步:
将imgcode.php放到control 文件夹下:
imgcode.php 内容如下:
<?php
class Control_ImgCode extends QUI_Control_Abstract
{
function render()
{
//$udi = $this->get('udi', 'default/imgcode');
$id = h($this->id());
$url = h(url('default::default/imgcode', array('rand' => '_RAND_')));
$out = "<input type=\"text\" ";
$out .= $this->_printIdAndName();
$out .= $this->_printAttrs('id, name');
$out .= $this->_printDisabled();
$out .= " />\n";
$out .= <<<EOT
<span id="{$id}_span">
<img id="{$id}_img" src="{$url}" border="0" style="cursor: pointer;" title="点击更换图像" />
</span>
EOT;
return $out;
}
}
第三步:在登陆的yaml文件中
# ~form 开头的内容用于指定表单属性
~form:
_subject: "用户登录"
# 指定字段及过滤器等信息
username:
_ui: textbox
_filters: ['trim', 'strtolower']
_label: "帐户 号"
_class: small
password:
_ui: password
_filters: ['trim', 'strtolower']
_label: "登录密码"
_class: small
imgcode:
_ui: ImgCode
_filters: ['trim', 'strtolower']
_label: "验证码"
_class: small
第四步:在登录方法(控制器)中验证
if ($this->_context->isPOST() && $form->validate($_POST))
{
try
{
if (!Helper_ImgCode::isValid($this->_context->imgcode))
{
$form['imgcode']->invalidate("您输入的验证码 < {$this->_context->imgcode} > 错误!");
}else{
.................................//省略以后代码
} |
|