我已经使用generate:bundle
生成了一个包(@ShopfishApiBundle
),就像我有很多次。它已自动在AppKernel
中注册该软件包,并将软件包routing.yml
的加载也添加到app/Resource/config/routing.yml
。这是一个Sylius
安装运行中Symfony 2.3
Symfony 2/Sylius - Bundle加载到AppKernel中,但无法加载资源
的@ShopfishApiBundle/Resource/config/routing.yml
看起来是这样的:
shopfish_api:
resource: "@ShopfishApiBundle/Controller/ProductController.php"
type: annotation
产品控制器看起来是这样的:
namespace Shopfish\Bundle\ApiBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
/**
* @Route("/api")
*/
class ProductController extends Controller
{
/**
* @Route("/products")
* @Method({"GET"})
*
* @Rest\View
*/
public function allAction()
{
$products = array();
return array('products' => $products);
}
}
加载任何页面瞬间产生了以下异常:
FileLoaderLoadException: Cannot load resource "@ShopfishApiBundle/Controller/". Make sure the "ShopfishApiBundle" bundle is correctly registered and loaded in the application kernel class.
In另一个Symfony2(版本2.4)的应用程序,我做了一个类似的包,这工作没有错误,我想在Sylius的东西混淆了这一点。你知道我可以在哪里解决这个问题吗?
注:我做了一个小测试,看看是否有直接无注释代码片段工作,这似乎工作。尽管我想使用FOS Rest捆绑软件,但使用了路由注释。
sf_api_controller:
pattern: /no-annotation-test
defaults:
_controller: ShopfishApiBundle:Product:all
你可以发布'AppKernel.php'的内容吗? – Touki
你还加载了SensioFrameworkExtraBundle吗? –
不,我确实没有,我不知道它是需要在控制器中导入带注释的路由。感谢您的黄金提示! – Mirage