PUGX / PUGXMultiUserBundle

An extension for FOSUserBundle to handle users of different types. Compatible with Doctrine ORM.
163 stars 96 forks source link

trouble making the profile Edit work #2

Closed leopro closed 11 years ago

leopro commented 11 years ago

https://github.com/PUGX/PUGXAutoCompleterBundle/issues/1

I am having trouble making the profile Edit work.

Mainly one of two issues seems to occur:

1) the profile edit of the FOS User bundle says: Method "user" for object "Symfony\Component\Form\FormView" does not exist in FOSUserBundle:Profile:edit.html.twig at line 14

That is what happens if try to access /profile/edit of the FOS User Bundle

2) If I have my own Profile controller which I do and try to access my own profile edit method on disctinct controllers based on the discriminator class then the editAction comes up with a blank form.

Here is the code regarding that.... any help would be greatly appreciated.

<?php

namespace MHO\VmpBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller as BaseController;
use Symfony\Component\HttpFoundation\RedirectResponse;

class ProfileVmpPhysicianController extends BaseController
{
    public function editAction()
    {
        $discriminator = $this->container->get('pugx_user_discriminator');
        $discriminator->setClass('MHO\VmpBundle\Entity\VmpPhysician',$persist = true);
        $form = $discriminator->getProfileForm();
        $this->container->set('fos_user.profile.form', $form);

        return $this->container->get('templating')->renderResponse('MHOVmpBundle:Profile:profile_vmp_physician.html.twig', array(
            'form' => $form->createView(),
        ));
    }
}

and here my form type class:

<?php

namespace MHO\VmpBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use FOS\UserBundle\Form\Type\ProfileFormType as BaseType;

class ProfileVmpPhysicianFormType extends BaseType
{    
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        parent::buildForm($builder, $options);

        $builder
            ->add("username", "text", array( 'attr' => array(
                'readonly' =>'readonly', 
                'class' => 'form-disabled' )))
            ->add("email", "email", array( 'attr' => array(
                'readonly' =>'readonly', 
                'class' => 'form-disabled' )))
            ->add("firstname", "text", array( 'attr' => array(
                'readonly' =>'readonly', 
                'class' => 'form-disabled' )))
            ->add("lastname", "text", array( 'attr' => array(
                'readonly' =>'readonly', 
                'class' => 'form-disabled' )))
            ->add("middlename", "text", array( 
                'attr' => array('readonly' =>'readonly', 
                'class' => 'form-disabled' )))
            ->add('suffix', "text", array( 'attr' => array(
                'readonly' =>'readonly', 
                'class' => 'form-disabled' )))
            ->add('homeAddress1', "text", array( 
                'label' => 'Address', ))
            ->add('homeAddress2', "text", array( 
                'label' => 'Address', 'required' => false, ))           
            ->add('homeCity', "text", array( 
                'label' => 'City', ))
            ->add('homeState', "text", array( 
                'label' => 'State',))
            ->add('homeZipCode', 'text', array('pattern'=>'[0-9]{5}', 'label' => 'Zipcode',  'attr'=>array( 'maxlength' => '5')))
            ->add('officePhone', "text", array( 
                'label' => 'Office phone', ))
            ->add('fax')
            ->add('cellPhone', "text", array( 
                'label' => 'Mobile', ))
            ->add('npi', 'text', array('pattern'=>'[0-9]{10}', 'attr'=>array( 'maxlength' => '10')))
        ;

    }

    public function getName()
    {
        return 'fos_user_profile_form';
    }

    protected function buildUserForm(FormBuilderInterface $builder, array $options)
    {
        parent::buildUserForm($builder, $options);
    }
}

Any ideas on what I could to get this to work?

leopro commented 11 years ago

@manoflamanchi which branch are you using?

gyalamanchi commented 11 years ago

Dev master

Sent from my iPhone

On Nov 12, 2012, at 7:35 AM, Leonardo Proietti notifications@github.com wrote:

@manoflamanchi which branch are you using?

— Reply to this email directly or view it on GitHub.

gyalamanchi commented 11 years ago
"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",
    "doctrine/doctrine-migrations-bundle": "dev-master",
    "friendsofsymfony/user-bundle": "v1.3.0",
    "sonata-project/admin-bundle": "dev-master",
    "sonata-project/doctrine-orm-admin-bundle": "dev-master",
    "sonata-project/user-bundle": "dev-master",
    "sonata-project/cache-bundle": "dev-master",
    "sonata-project/block-bundle": "dev-master",
    "sonata-project/jquery-bundle": "dev-master",
    "knplabs/knp-menu-bundle": "1.1.*",
    "knplabs/knp-menu": "1.1.*",
    "pugx/multi-user-bundle": "1.4.x-dev",
    "vresh/twilio-bundle": "dev-master"
},

So i tried this composer.json to match what you have in the PUGXMultiUserSandbox and the composer.phar update isnt working because "sonata-project/user-bundle": "dev-master" is requiring "friendsofsymfony/user-bundle" to be at dev-master. Will that still work if I set "friendsofsymfony/user-bundle" to "dev-master" ?

I installed the PUGXMultiUserSandbox exactly to spec and it seems to work.

Hmmm... any ideas Leo?

gyalamanchi commented 11 years ago

Problem 1

Uggg.... I don't know how to get around this. I need the Sonata User Bundle so I can have the login for the admin and a base user class that can work for both the admin and normal site.

It seems though that the PUGX will only work with fos user bundle 1.3.0 when i use pugx 1.4.x-dev.

The sonata user bundle wants the fos user bundle at branch dev-master.

Any ideas on how I can just make these three get along?

garak commented 11 years ago

You should use

"pugx/multi-user-bundle": "dev-master",

instead of

"pugx/multi-user-bundle": "1.4.x-dev",
gyalamanchi commented 11 years ago

When I do that and access the /profile/edit I get this error...

Method "user" for object "Symfony\Component\Form\FormView" does not exist in FOSUserBundle:Profile:edit.html.twig at line 14

If I go to my own custom profile edit located at /profile/edit/vmp_physician to specify a custom profile edit view then I get a different issue... my profile edit form is empty.

Is my Profile controller correct?

use Symfony\Bundle\FrameworkBundle\Controller\Controller as BaseController;
use Symfony\Component\HttpFoundation\RedirectResponse;

class ProfileVmpPhysicianController extends BaseController
{
    public function editAction()
    {
        $discriminator = $this->container->get('pugx_user_discriminator');
        $discriminator->setClass('MHO\VmpBundle\Entity\VmpPhysician',$persist = true);
        $form = $discriminator->getProfileForm();
        $this->container->set('fos_user.profile.form', $form);

        return $this->container->get('templating')->renderResponse('MHOVmpBundle:Profile:profile_vmp_physician.html.twig', array(
            'form' => $form->createView(),
        ));
    }
}
leopro commented 11 years ago

I really don't understand why you need to override the profile controller; anyway, take a look to:

PUGX\MultiUserBundle\Listener\ControllerHandlerListener PUGX\MultiUserBundle\Controller\ControllerHandler

you can try extending FOS\UserBundle\Controller\ProfileController

gyalamanchi commented 11 years ago

I will give that a try. I guess I only was trying to override the profile controller so I could pass in a different view for each user type. I have in this system three user classes... manager, physician, patient. Only patient & physician use the front-end site. I didn't see how to pass in a custom view without making two Profile controllers for each.

I notice that in the sandbox example, you just use the fos user profile edit form regardless of the user type and the magic just works. However, I dont know how that allows me to customize the view for each user type.

One a side note, what what I have to implement in the Profile controller to pass in a custom view?

Would this code even work?

public function editAction()
{
    $discriminator = $this->container->get('pugx_user_discriminator');
    $discriminator->setClass('MHO\VmpBundle\Entity\VmpPhysician',$persist = true);
    $form = $discriminator->getProfileForm();
    $this->container->set('fos_user.profile.form', $form);

    return $this->container->get('templating')->renderResponse('MHOVmpBundle:Profile:profile_vmp_physician.html.twig', array(
        'form' => $form->createView(),
    ));
}

I just want the code to be able to access the user in the twig and be able to render the right twig template based on the view.

gyalamanchi commented 11 years ago

Hmm.. looks like the bug is on my side. I updated the pugx and fos to both use the dev-master and it seems to work on the sandbox example I used.

I will track it down. I have a rather complex configuration using the Sonata User class being the base class.

gyalamanchi commented 11 years ago

Leonardo, you can close this issue. I got it to work!!! And thanks a lot for the bundle.

The reason it wasn't working was that I had some erroneous version of MHO/VmpBundle/Resources/views/Profile/edit.html.twig .... and that file was trying to override the FOS user bundle's edit.html.twig but not with the right code.... so that was the problem.