我使用最新版本的 Silex(不是 Phar 版本)。我在实现表单服务提供者和翻译提供者时遇到问题,我收到以下错误:
“致命错误:第 47 行的 D:\xampp\htdocs\mytest\vendor\symfony\translation\Symfony\Component\Translation\Loader\XliffFileLoader.php 中找不到类 'Symfony\Component\Config\Resource\FileResource'”
如果我禁用此行,表单会显示并且一切正常(翻译除外)。我什至收到消息,可以从德语表格的一个选项中进行选择。
$app->register(new Silex\Provider\ValidatorServiceProvider());
请给我一个提示如何解决这个问题。请在下面查看我的代码和我的 composer.json 文件:
应用程序.php:
<?php
$app = new Silex\Application();
$app['debug'] = true;
use Silex\Provider\FormServiceProvider;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
$app->register(new Silex\Provider\FormServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider(), array(
'locale' => 'de',
'fallback_locale' => 'en',
));
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/../views',
));
// Sample from silex-homepage
$app->match('/form', function (Request $request) use ($app) {
// some default data for when the form is displayed the first time
$data = array(
'name' => 'Your name',
'email' => 'Your email',
);
$form = $app['form.factory']->createBuilder('form', $data)
->add('name')
->add('email')
->add('gender', 'choice', array(
'choices' => array(1 => 'male', 2 => 'female'),
'expanded' => true,
))
->getForm();
if ('POST' == $request->getMethod()) {
$form->bindRequest($request);
if ($form->isValid()) {
$data = $form->getData();
// do something with the data
// redirect somewhere
return $app->redirect('...');
}
}
// display the form
return $app['twig']->render('test.html', array('form' => $form->createView()));
});
return $app;
?>
作曲家.json:
{
"require": {
"silex/silex": "1.0.*",
"symfony/browser-kit": "2.1.*",
"symfony/console": "2.1.*",
"symfony/config": "2.1.*",
"symfony/css-selector": "2.1.*",
"symfony/dom-crawler": "2.1.*",
"symfony/filesystem": "2.1.*",
"symfony/finder": "2.1.*",
"symfony/form": "2.1.*",
"symfony/locale": "2.1.*",
"symfony/process": "2.1.*",
"symfony/security": "2.1.*",
"symfony/serializer": "2.1.*",
"symfony/translation": "2.1.*",
"symfony/validator": "2.1.*",
"symfony/monolog-bridge": "2.1.*",
"symfony/twig-bridge": "2.1.*",
"monolog/monolog": ">=1.0.0,<1.2-dev",
"twig/twig": ">=1.2.0,<2.0-dev",
"doctrine/dbal": "2.1.*",
"swiftmailer/swiftmailer": "4.1.*"
},
"autoload": {
"psr-0": {"Acme": "src/"}
}
}