我使用以下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 回答
见Doc . 对于您的symfony版本,您需要此捆绑包的另一个版本 . 尝试安装它而不在
composer.json
中提供版本 .根据警告,尝试通过从PEAR的sitweb https://pecl.php.net/package/yaml下载它来安装php_yaml扩展 .
选择稳定版本并将解压缩后的dll复制到** C:\ xampp \ php \ ext **
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标记,请使用此,如果仍有问题打开另一个问题 .