sfCaptchaGDPlugin 插件用于生成验证码,在最近的使用中发现还是有很多地方要值得注意特作此记录:
一、安装
1、将插件下载下来解压去掉版本号放进plugins文件夹内
2、在/config/ProjectConfiguration.class.php 文件里加入$this->enablePlugins('sfCaptchaGDPlugin');
3、修改 apps/frontend/config/settings.yml
添加如下代码:
enabled_modules: [default, sfCaptchaGD]
standard_helpers: [Partial, Cache, I18N]
i18n: true
4、symfony cc
7、修改plugins/sfDoctrineGuardPlugin/lib/form/doctrine/sfGuardFormSignin.class.php( 其他以此类推)
configure函数里添加如下代码:
$this->widgetSchema['captcha'] = new sfWidgetCaptchaGD();
$this->validatorSchema['captcha'] = new sfCaptchaGDValidator(array ('length' => 4));
8、修改plugins/sfDoctrineGuardPlugin/modules/sfGuardAuth/_signin_form.php
在<table></table里添加
<?php echo $form['captcha']->render(array('id'=>'tdck', 'value'=>'请输入验证码'))?>(或其他输出表单字段的形式)
9、修改apps/frontend/config/app.yml
添加如下代码:
all:
sf_captchagd:
image_width: 200 # image width in pixels
image_height: 30 # image height in pixels
chars: "123456789" # possible chars in captcha
length: 4 # length of captcha
font_size: 18 # font size
force_new_captcha: false # if true - captcha regenerated EVERY request, even if user input true value before
# possible chars colors
font_color: ["252525", "8b8787", "550707", "3526E6", "88531E"]
# chars fonts
fonts: ["akbar/akbar.ttf", "brushcut/BRUSHCUT.TTF", "molten/molten.ttf", "planet_benson/Planetbe.ttf", "whoobub/WHOOBUB_.TTF"]
background_color: DDDDDD # image background color
border_color: 000000 # image border color
二、注意
1、此时我们如果访问我们的登陆页面会发现验证码图片未出现则在plugins/sfCaptchaGDPlugin/modules/sfCaptchaGD/里新建config文件夹并在内新建security.yml
文件并添加如下代码:
default:
is_secure: false
2、如验证码图片还未出现则查看php.ini文件里的extension=php_gd2.dll是否开启,如未开启则去掉其前面的分号(call to undefined function imagecreatetruecolor() in也是按此方法解决)