Search code examples
phpsymfonybundlecaptchasymfony-2.8

Using Captcha with Symfony2 (2.8)


I installed Captcha bundle using this following Instruction:

  1. Add "gregwar/captcha-bundle": "1.0.0" to require section in composer.json
  2. Run Windows PowerShell in root and call php composer.phar update
  3. Console outputs

Warning: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_yaml.dll' - Nie mo┐na odnalečŠ okreťlonego modu│u. in Unknown on line 0 Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files Incenteev\ParameterHandler\ScriptHandler::buildParameters Updating the "app/config/parameters.yml" file Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap

Warning: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_yaml.dll' - Nie mo┐na odnalečŠ okreťlonego modu│u. in Unknown on line 0 Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

Warning: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_yaml.dll' - Nie mo┐na odnalečŠ okreťlonego modu│u. in Unknown on line 0

// Clearing the cache for the dev environment with debug true

[OK] Cache for the "dev" environment (debug=true) was successfully cleared.

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

Warning: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_yaml.dll' - Nie mo┐na odnalečŠ okreťlonego modu│u. in Unknown on line 0

Trying to install assets as relative symbolic links.

        Bundle                 Method / Error   

WARNING FrameworkBundle copy
WARNING JMSTranslationBundle copy

! [NOTE] Some assets were installed via copy. If you make changes to these assets you have to run this command again.

[OK] All assets were successfully installed.

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

  1. Following instruction I can skip this step

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

but my autoload.php files looks following:

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. I enabled bundle:

    // app/appKernel.php
    
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Gregwar\CaptchaBundle\GregwarCaptchaBundle(),
        );
    }
    
  2. Last instalation step is add gregwar_captcha: ~ to app/config/config.yml and it's done.

Now I'm trying to use it im my controller.

    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(),
            )
        );
    }

I get error:

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)

Where did I wrong?


Solution

  • See Doc. For your version of symfony you need another version of this bundle. Try installing it without providing version in composer.json.