在routing.yml中,我可以使用以下命令重新获取其他路由配置:
leaphly_cart:
type: rest
resource: '@AppXXXBundle/Resources/config/rest.xml'
prefix: /api/v1/
和rest.xml文件:
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<import id="carts" type="rest" resource="leaphly_cart.cart.limited.controller" name-prefix="api_1_" />
<import id="cartItems" type="rest" resource="leaphly_cart.cart_item.limited.controller" name-prefix="api_1_" parent="carts" />
<import id="carts_full" type="rest" resource="leaphly_cart.cart.full.controller" name-prefix="api_1_full_" prefix="/full" />
<import id="cartItems_full" type="rest" resource="leaphly_cart.cart_item.full.controller" name-prefix="api_1_full_" parent="carts_full" prefix="/full" />
<import id="cartTransitions" type="rest" resource="Leaphly\CartBundle\Controller\CartTransitionsController" name-prefix="api_1_" parent="carts" />
</routes>
但这不起作用......并显示错误:
InvalidArgumentException: [ERROR 1845] Element '{http://symfony.com/schema/routing}routes': No matching global declaration available for the validation root. (in /var/www/app.com/web/ - line 5, column 0)
这有什么不对?
答案 0 :(得分:3)
XML验证失败,因为存在symfony的标准路由xsd不包含/允许的属性(即name-prefix
属性)。
将FOSRestBundle/Resources/config/schema/routing/
rest_routing-1.0.xsd
添加到您的xml文件中,验证不会失败。