As symfony2 relies on namespaces, you can share classes between them easily.
Let's say you defined your entities in FrontendBundle
, they will be like:
namespace Acme\FrontendBundle\Entity;
/** @ORM annotations stuff */
class MyEntity
{
protected $id;
...
}
You can then refer to them either by creating from scratch:
$newEntity = new \Acme\FrontendBundle\Entity\MyEntity();
or by importing them via use
:
namespace Acme\BackendBundle\Controller;
use Acme\FrontendBundle\Entity\MyEntity;
class AdminController extends Controller
{
public someAction()
{
$newEntity = new MyEntity();
}
}
Doctrine repositories use a slightly different notation:
$this-> getDoctrine()
-> getEntityManager()
-> getRepository('FrontendBundle:MyEntity')
-> findAll();
being it NameBundle:EntityName
.
Refer to symfony best practices to get a better clue!