1、使用验证码了时:使用Composer
安装think-captcha
扩展包:
composer require topthink/think-captcha
报错:Fatal error: Class 'Route' not found in D:\WWW\JVS\tp5\vendor\topthink\think-captcha\src\helper.php on line 12
查看代码:
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <[email protected]>
// +----------------------------------------------------------------------
Route::get('captcha/[:id]', "\\think\\captcha\\CaptchaController@index");
Validate::extend('captcha', function ($value, $id = '') {
return captcha_check($value, $id);
});
Validate::setTypeMsg('captcha', ':attribute错误!');
修改为:
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <[email protected]>
// +----------------------------------------------------------------------
\think\Route::get('captcha/[:id]', "\\think\\captcha\\CaptchaController@index");
\think\Validate::extend('captcha', function ($value, $id = "") {
return captcha_check($value, $id, (array)\think\Config::get('captcha'));
});
\think\Validate::setTypeMsg('captcha', '验证码错误!');
就可以访问了。