symfony 2.8 generated crud controller with errors

时间:2016-02-02 10:40:18

标签: symfony

I try generate CRUD controllers for my entities.

For example I wanna generate CRUD controller for AppBundle\Entity\User\User:

namespace AppBundle\Entity\User;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\Group;
/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User extends BaseUser
{

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
}

Generate entities:

$ app/console generate:doctrine:entities AppBundle

Generate crud:

$ app/console doctrine:generate:crud --entity=AppBundle:User\User

This command generete follow controller:

class UserController extends Controller
{
    /**
     * Lists all User\User entities.
     *
     * @Route("/", name="user_user_index")
     * @Method("GET")
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getManager();

        $user\Users = $em->getRepository('AppBundle:User\User')->findAll();

        return $this->render('user/user/index.html.twig', array(
            'user\Users' => $user\Users,
        ));
    }

    /**
     * Finds and displays a User\User entity.
     *
     * @Route("/{id}", name="user_user_show")
     * @Method("GET")
     */
    public function showAction(User $user\User)
    {

        return $this->render('user/user/show.html.twig', array(
            'user\User' => $user\User,
        ));
    }
}

What the $user\Users? Symfony 2.8! Maybe I can't use more directories in the Entity folder?

1 个答案:

答案 0 :(得分:1)

如果您在CRUD生成命令中使用了与此问题中相同的命名空间,我希望symfony感到困惑。

你曾经使用过:

AppBundle\Entity\User\User

请注意额外的\User

如果这不是拼写错误,您的实体应该驻留在基本实体目录中。不寻常的道路可能让它感到困惑。

然而,人们会想到,generate命令应该首先验证字符串。