Let’s say I have two Bundles :
Compagny\InterfaceBundleCompagny\UserBundle
How can I load an Entity of UserBundle in the controller of InterfaceBundle ?
The Controller of my Compagny/InterfaceBundle :
<?php
// src/Compagny/InterfaceBundle/Controller/DefaultController.php
namespace Compagny\InterfaceBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Compagny\UserBundle\Entity; // I believed this line will do the trick, but it doesn't
class DefaultController extends Controller
{
public function indexAction()
{
$user = new User();
}
}
The Entity of my Compagny/UserBundle :
<?php
namespace Compagny\UserBundle\Entity
class User {
public $name;
public function setName($name) {
// ...
}
public function getName() {
// ...
}
}
(Let’s says for this example that the User class doesn’t use Doctrine2, because it doesn’t need to connect to the database).
You can of course, you are just using a class from another namespace. The fact that it is an entity is not important at all! You can of course query the entity manager for that entity as well.