-1

I am not able to use CRUD generate with Symfony. I believe this most probably depends on Symfony version. Which version of Symfony is the best to use?

Today i have updated Symfony:

c:\Bitnami\wampstack-5.5.30-0\sym_prog>php symfony self-update

I have got the message : updating Symfony Installer to 1.4.0

Later i have made a new project:

c:\Bitnami\wampstack-5.5.30-0\sym_prog\proj2>php symfony new proj2 lts

// lts means long term support And have got a message: OK Symfony 2.8.0 was successfully installed. Now you can: * Change your current directory to C:\Bitnami\wampstack-5.5.30-0\sym_prog\prj2 * Configure your application in app/config/parameters.yml file. * Run your application: 1. Execute the php app/console server:run command. 2. Browse to the http://localhost:8000 URL. * Read the documentation at http://symfony.com/doc

After generating entities i have got problems with crud.

c:\Bitnami\wampstack-5.5.30-0\sym_prog\proj2>php app/console doctrine:generate:crud MeetingBundle:User
The Entity shortcut name [MeetingBundle:User]:
Do you want to generate the "write" actions [no]? Yes
Configuration format (yml, xml, php, or annotation) [annotation]:
Routes prefix [/user]:

Although crud generates controller and views (the latter are generated not in the bundle/resources/views, but in app/resources/views), but crud does not generate forms, thus i can not create/update/view/delete user or other entities!

I believe it depends only on Symfony version. Thus which version is the best to use?

olga
  • 959
  • 1
  • 15
  • 42

2 Answers2

0

I do not know which Symfony version generates forms for crud.

But in my case i just created custom form: C:\Bitnami\wampstack-5.5.30-0\sym_prog\proj2\src\MeetingBundle\Form\UserType.php

<?php

namespace MeetingBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class UserType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('username')
            ->add('password')
            ->add('email')
            ->add('phone')
           // ->add('roles') 
       /* ERROR: An exception has been thrown during the rendering of a template 
  ("Notice: Array to string conversion") in form_div_layout.html.twig at line 13. 
                http://stackoverflow.com/questions/17314996/symfony2-array-to-string-conversion-error
                */
            ->add('isActive')
            ->add('events')
                // createdAt
        ;
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'MeetingBundle\Entity\User'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'meetingbundle_user';
    }
}

And used it from Controller: C:\Bitnami\wampstack-5.5.30-0\sym_prog\proj2\src\MeetingBundle\Controller\UserController.php

...
use MeetingBundle\Form\UserType;
....
class UserController extends Controller {
...
    public function editAction(Request $request, User $user)
    {
...
        $editForm = $this->createForm(new UserType(), $user);
olga
  • 959
  • 1
  • 15
  • 42
0

using command:

>php app/console doctrine:generate:crud

Symfony version 2.7.7 and Symfony version 2.3.35 - generates Entity views in src/Namespace/Bundle/Resources/views/EntityName folder. It also generates controller and folder Form with file EntitnyNameType.php. Crud is fully functioning.

Symfony version 2.8.0 (Long term support) - generates views for entity in app/Resources/views/EntitnyName folder and also generates controller. It does not generate Form, thus CRUD is not working.

p.s. To check which Symfony version you use:

c:\Bitnami\wampstack-5.5.30-0\sym_prog\star>php app/console --version

To user certain version of Symfony for your project you have to tell this during the project creation:

$ symfony new my_project_name 2.6

http://symfony.com/doc/current/book/installation.html

If anyone can give more information about which Symfony version is better, please let me to know.

olga
  • 959
  • 1
  • 15
  • 42