返回列表 回复 发帖

[推荐] Qeephp验证码组件使用

第一步:/**
* 默认控制器
*/
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{
.................................//省略以后代码

}
原因预示了结果,方法注定了结局,种子孕育了果实!
来的同胞留下脚印!支持一下,谢谢!
原因预示了结果,方法注定了结局,种子孕育了果实!
这大热天怎么好冷啊!!!!!!!
原因预示了结果,方法注定了结局,种子孕育了果实!
大哥,你少发个helper文件的内容啊
谢谢了,Helper 内容Qeephp自带的啊,不用添加,它是指导你怎么使用的!
原因预示了结果,方法注定了结局,种子孕育了果实!
晕,  小弟斗胆求教把view中登录页面的验证码代码也贴出来
楼上的你只要按我的步骤走下来,你的登录页面绝对有验证码,它是在YAML文件里配置,通过视图渲染产生的!
原因预示了结果,方法注定了结局,种子孕育了果实!
大哥,为什么在http://localhost:9000/marxuestc/public/default/imgcode有验证码出来,在http://localhost:9000/marxuestc/public/user/imgcode却没有验证码出来呢?
imgcode.php 内容:
$url     = h(url('default::default/imgcode', array('rand' => '_RAND_')));
告诉解析器验证码的控制器是Default ,参照修改
原因预示了结果,方法注定了结局,种子孕育了果实!
返回列表