我在Symfony2 Web应用程序中添加了新功能,经过一些开发后,编辑用户功能停止工作。
出于某种原因,错误显示在edit user screen
中,而不在show user
中。
错误:
The parameter "fos_user.template.theme" must be defined.
500 Internal Server Error - InvalidArgumentException
editAction
方法:
/**
* Edit the user
*/
public function editAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
$form = $this->container->get('fos_user.profile.form');
$formHandler = $this->container->get('fos_user.profile.form.handler');
$process = $formHandler->process($user);
if ($process) {
$this->setFlash('notice', 'As alterações foram feitas com sucesso.');
return new RedirectResponse($this->container->get('router')->generate('fos_user_profile_show'));
}
return $this->container->get('templating')->renderResponse(
'FOSUserBundle:Profile:edit.html.'.$this->container->getParameter('fos_user.template.engine'),
array('form' => $form->createView(), 'theme' => $this->container->getParameter('fos_user.template.theme'))
);
}
我相信config.yml上缺少某些内容,但我无法在fos_user.template.theme
上添加正确的参数:
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: App\UserBundle\Entity\User
registration:
form:
type: duo_vozi_user_registration
profile:
form:
type: duo_vozi_user_profile
from_email:
address: vozi@vozi.com.br
sender_name: VOZI
这些是使用过的组件的版本:
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.1.*",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.0.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.1.*",
"symfony/monolog-bundle": "2.1.*",
"sensio/distribution-bundle": "2.1.*",
"sensio/framework-extra-bundle": "2.1.*",
"sensio/generator-bundle": "2.1.*",
"jms/security-extra-bundle": "1.2.*",
"jms/di-extra-bundle": "1.1.*",
"doctrine/doctrine-fixtures-bundle": "dev-master",
"gedmo/doctrine-extensions": "dev-master",
"friendsofsymfony/user-bundle": "1.3.1",
"brazilianfriendsofsymfony/sync-content-bundle": "dev-master",
"brazilianfriendsofsymfony/brasil-bundle":"dev-master",
"brazilianfriendsofsymfony/settings-management-bundle":"dev-master",
"brazilianfriendsofsymfony/pagseguro-bundle":"dev-master",
"brazilianfriendsofsymfony/twig-extensions-bundle":"dev-master",
"knplabs/knp-menu-bundle":"dev-master",
"duo/cms-bundle": "v1.1.9"
},
答案 0 :(得分:0)
经过一些研究以找到控制器代码的来源,它似乎来自旧版本的FOSUserBundle (1) (2) (3)。因此,我建议您升级Symfony2或使用最新版本的FOSUserBundle并使用文档的最新版本。
答案 1 :(得分:0)
如果您使用twig作为模板引擎,请删除代码中对$this->container->getParameter('fos_user.template.theme')
的所有调用,并将其替换为静态字符串'twig'
。
自FOSUserBundle removed the option to switch to a different templating engine以来就是如此。
@Victor,editAction()
方法将成为:
/**
* Edit the user
*/
public function editAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
$form = $this->container->get('fos_user.profile.form');
$formHandler = $this->container->get('fos_user.profile.form.handler');
$process = $formHandler->process($user);
if ($process) {
$this->setFlash('notice', 'As alterações foram feitas com sucesso.');
return new RedirectResponse($this->container->get('router')->generate('fos_user_profile_show'));
}
return $this->container->get('templating')->renderResponse(
'FOSUserBundle:Profile:edit.html.twig',
array('form' => $form->createView(), 'theme' => $this->container->getParameter('fos_user.template.theme'))
);
}