Symfony bundle namespacing
I set a Bundle which is called Mine:
src/Mine/DemoBundle/Controller
src/Mine/DemoBundle/Entity/user/User.php
my routing is:
defaults: { _controller: MineDemo:User:create }
UserController.php starts like this:
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();
// ...
}
and User.php is:
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;
}
}
I keep getting the error:
Fatal error: Class 'Mine\DemoBundle\Entity\User' not found
in C:\xampp\htdocs\Symfony\src\Mine\DemoBundle\Controller\UserController.php on line 12
The namespace on your class should be
namespace Mine\DemoBundle\Entity;
instead of
namespace Mine\DemoBundle\Entity\User;
精彩评论