Hãy nói rằng tôi có hai Gói:Làm thế nào để tải một Entity từ một Bundle trên Symfony2
Compagny\InterfaceBundle
Compagny\UserBundle
Làm thế nào tôi có thể tải một Entity của UserBundle trong bộ điều khiển của InterfaceBundle ?
Các Controller
của Compagny/InterfaceBundle
tôi:
<?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();
}
}
Các Entity
của tôi Compagny/UserBundle
:
<?php
namespace Compagny\UserBundle\Entity
class User {
public $name;
public function setName($name) {
// ...
}
public function getName() {
// ...
}
}
(Hãy nói ví dụ này mà lớp người dùng không sử dụng Doctrine2, bởi vì nó doesn' t cần phải kết nối với cơ sở dữ liệu).