Doctrine实体来自Symfony控制器中的其他Bundle



我尝试在Symfony控制器中使用另一个Bundle的实体:

use AcmeTestBundleEntityNeighbour;
use AppBundleEntityHome;
class TestController extends Controller {
    public function testAction(Home $home, Neighbour $neighbour) { 
        //
    }
}

但是会抛出404错误:

AcmeTestBundleEntityNeighbour object not found

这与真正不存在的对象(如neighborx)不同,它抛出500错误:

AcmeTestBundleEntityNeighbour does not exist

对象存在,它应该可以工作,因为这可以工作:

use AcmeTestBundleEntityNeighbour;
use AppBundleEntityHome;
class TestController extends Controller {
    public function testAction(Home $home) { 
        $thread = new ForumThread();
    }
}

好吧,我自己已经找到答案了。我必须指定route变量:

/home/{id}/neighbour/{nid} #before
/home/{id}/neighbour/{neighbour} #after

但是我不能完全理解它。为什么{id}不一定是{home}?{id}是默认的第一个参数id吗?

最新更新