所以我设置了一个名为Mine的Bundle:
src/Mine/DemoBundle/Controller
src/Mine/DemoBundle/Entity/user/User.php
src/Mine/DemoBundle/Entity/user/User.php
我的路由是:
UserController.php就像这样开始:
defaults: { _controller: MineDemo:User:create }
和User.php是:
namespace Mine\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Mine\DemoBundle\Entity\User;
class UserController extends Controller
{
public function createAction()
{
$user = new User();
$user->setName('Jonathan H. Wage');
$em = $this->get('doctrine.orm.entity_manager');
$em->persist($user);
$em->flush();
// ...
}
我一直收到错误:
namespace Mine\DemoBundle\Entity\User;
/**
* Mine\DemoBundle\Entity\User\User
*/
class User
{
/**
* @var integer $id
*/
private $id;
/**
* @var string $name
*/
private $name;
/**
* Get id
*
* @return integer $id
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get name
*
* @return string $name
*/
public function getName()
{
return $this->name;
}
}
感谢您的帮助
答案 0 :(得分:3)
您班上的名称空间应为
namespace Mine\DemoBundle\Entity;
而不是
namespace Mine\DemoBundle\Entity\User;