1

我使用以下说明安装了验证码包:

  1. 添加"gregwar/captcha-bundle": "1.0.0"require部分composer.json
  2. Windows PowerShell以root运行并调用php composer.phar update
  3. 控制台输出

警告:PHP 启动:无法加载动态库 'C:\xampp\php\ext\php_yaml.dll' - Nie mo┐na odnalečŠ okreťlonego modu│u。在 Unknown on line 0 使用包信息加载 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' - Nie mo┐na odnalečŠ okreťlonego modu│u。在第 0 行的未知中 Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

警告:PHP 启动:无法加载动态库 'C:\xampp\php\ext\php_yaml.dll' - Nie mo┐na odnalečŠ okreťlonego modu│u。在第 0 行的未知中

// 使用 debug true 清除开发环境的缓存

[OK] "dev" 环境 (debug=true) 的缓存已成功清除。

Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets

警告:PHP 启动:无法加载动态库 'C:\xampp\php\ext\php_yaml.dll' - Nie mo┐na odnalečŠ okreťlonego modu│u。在第 0 行的未知中

尝试将资产安装为相对符号链接。

        Bundle                 Method / Error   

警告 FrameworkBundle 复制
警告 JMSTranslationBundle 复制

![注意] 一些资产是通过副本安装的。如果您对这些资产进行更改,则必须再次运行此命令。

[OK] 所有资产均已成功安装。

Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget

  1. 按照说明我可以跳过这一步

    // 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;
  1. 我启用了捆绑:

    // app/appKernel.php
    
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Gregwar\CaptchaBundle\GregwarCaptchaBundle(),
        );
    }
    
  2. 添加最后一个安装步骤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)

我哪里错了?

4

3 回答 3

1

文档。对于你的 symfony 版本,你需要这个包的另一个版本。尝试安装它而不提供composer.json.

于 2016-01-27T10:17:13.270 回答
0

根据警告,尝试通过从 PEAR 的网站https://pecl.php.net/package/yaml下载来安装 php_yaml 扩展。

选择稳定版本,解压后的dll复制到**C:\xampp\php\ext**

于 2016-01-27T10:21:12.600 回答
0

https://github.com/symfony/symfony/blob/2.7/UPGRADE-2.1.md#form

如果您检查升级文档,与 Symfony 2.1 FormTypeInterface 相关的版本发生了变化,并且它是在 https://github.com/Gregwar/CaptchaBundle/blob/v1.0.0/Type/CaptchaType.php中使用的 BC 中断

所以 Symfony 2.8 与此捆绑包版本 1.0.0 不兼容有 2.0 版本标记,请使用此版本,如果仍有问题,请打开另一个问题。

于 2016-01-27T10:28:03.853 回答