我已经多次使用 @ShopfishApiBundle
生成了一个包( generate:bundle
)。它已经自动在 AppKernel
中注册了包,并将包的 routing.yml
加载添加到 app/Resource/config/routing.yml
中。这是在运行 Sylius
的 Symfony 2.3
安装中@ShopfishApiBundle/Resource/config/routing.yml
如下所示:
shopfish_api:
resource: "@ShopfishApiBundle/Controller/ProductController.php"
type: annotation
产品 Controller 如下所示:
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.
在另一个 Symfony2(2.4 版)应用程序中,我制作了一个类似的包,并且没有错误,我在想 Sylius 中的某些东西把它搞砸了。你知道我可以在哪里解决这个问题吗?
注意:我做了一个小测试,看看直接无注释的代码片段是否有效,这似乎有效。虽然我想使用 FOS Rest 包,使用路由注释。
sf_api_controller:
pattern: /no-annotation-test
defaults:
_controller: ShopfishApiBundle:Product:all
最佳答案
我没有在我的 SensionFrameworkExtraBundle
中注册必要的 AppKernel.php
:new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle()
谢谢,@pazi!
关于Symfony 2/Sylius - 在 AppKernel 中加载包但无法加载资源,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22866182/