Question

I'm adding new features in a Symfony2 Web Application, and after few development the edit user feature stop working.

For some reason the erro is showed in edit user screen, not in show user.

The error:

The parameter "fos_user.template.theme" must be defined.
500 Internal Server Error - InvalidArgumentException

The editAction method:

/**
 * 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'))
    );
}

I believe something is missing on config.yml, but I can't add the correct paramter on 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

These are the version of used components:

"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"
},
Was it helpful?

Solution

After some research to find the origin of your controller's code, it seems that it comes from an old version of FOSUserBundle (1) (2) (3). So I suggest you to upgrade your Symfony2 or use the last version of FOSUserBundle and use the last version of the documentation.

OTHER TIPS

If you use twig as your template engine, remove all calls to $this->container->getParameter('fos_user.template.theme') in your code and replace them with the static string 'twig'.

This is true since FOSUserBundle removed the option to switch to a different templating engine.

@Victor, the editAction() method would become :

/**
 * 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'))
    );
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top