首页 文章

使用Captcha与Symfony2(2.8)

提问于
浏览
1

我使用以下Instruction安装了Captcha软件包:

  • composer.json 中将 "gregwar/captcha-bundle": "1.0.0" 添加到 require 部分

  • 在root中运行 Windows PowerShell 并调用 php composer.phar update

  • 控制台输出

警告:PHP启动:无法加载动态库'C:\ xampp \ php \ ext \ php_yaml.dll' - Niemo┐naodnalečŠokreťlonegomodi│u . 在第0行的Unknown中使用包信息加载composer存储库更新依赖项(包括require-dev)无需安装或更新生成自动加载文件Incenteev \ ParameterHandler \ ScriptHandler :: buildParameters更新“app / config / parameters.yml”文件Sensio \ Bundle \ DistributionBundle \ Composer \ ScriptHandler :: buildBootstrap警告:PHP启动:无法加载动态库'C:\ xampp \ php \ ext \ php_yaml.dll' - Niemo┐naodnalečŠokreťlonegomodi│u . 在第0行的未知内容Sensio \ Bundle \ DistributionBundle \ Composer \ ScriptHandler :: clearCache警告:PHP启动:无法加载动态库'C:\ xampp \ php \ ext \ php_yaml.dll' - Niemo┐naodnalečŠokreťlonegomodi│ ü . 在第0行的Unknown中//使用debug true清除dev环境的高速缓存[OK]已成功清除“dev”环境(debug = true)的高速缓存 . Sensio \ Bundle \ DistributionBundle \ Composer \ ScriptHandler :: installAssets警告:PHP启动:无法加载动态库'C:\ xampp \ php \ ext \ php_yaml.dll' - Niemo┐naodnalečŠokreťlonegomodi│u . 在第0行的Unknown中尝试将资源安装为相对符号链接 . 捆绑方法/错误
警告FrameworkBundle副本警告JMSTranslationBundle副本! [注意]有些资产是通过副本安装的 . 如果对这些资产进行更改,则必须再次运行此命令 . [确定]所有资产都已成功安装 . Sensio \ Bundle \ DistributionBundle \ Composer \ ScriptHandler :: installRequirementsFile Sensio \ Bundle \ DistributionBundle \ Composer \ ScriptHandler :: prepareDeploymentTarget

  • 按照说明我可以跳过这一步
// app/autoload.php

$loader->registerNamspaces(array(
    // ...
    'Gregwar' => __DIR__.'/../vendor/bundles',
));

但我的autoload.php文件看起来如下:

use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;

error_reporting(error_reporting() & ~E_USER_DEPRECATED);

$loader = require __DIR__.'/../vendor/autoload.php';

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

return $loader;
  • 我启用了捆绑:
// app/appKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Gregwar\CaptchaBundle\GregwarCaptchaBundle(),
    );
}
  • 最后一个安装步骤是将 gregwar_captcha: ~ 添加到 app/config/config.yml 并完成 .

现在我正试图在我的控制器中使用它 .

public function registrationAction(Request $request)
    {
        $user = new Models\User();

        $form = $this->createFormBuilder($user)
            ->add('username', 'Symfony\Component\Form\Extension\Core\Type\TextType')
            ->add('birth', 'Symfony\Component\Form\Extension\Core\Type\DateType')
            ->add('captcha', 'captcha')
            ->add('save', 'Symfony\Component\Form\Extension\Core\Type\SubmitType', array('label' => 'Register'))
            ->getForm();

        $form->handleRequest($request);



        return $this->render(
             'CassyW2Bundle:User:registration.html.twig',
             array(
                'form' => $form->createView(),
            )
        );
    }

我收到错误:

Compile Error: Declaration of Gregwar\CaptchaBundle\Type\CaptchaType::buildView() must be compatible with Symfony\Component\Form\FormTypeInterface::buildView(Symfony\Component\Form\FormView $view, Symfony\Component\Form\FormInterface $form, array $options)

我哪里错了?

3 回答

相关问题