路径“”的参数“”必须与“ [^ /] ++”(给定的“”)匹配,以生成相应的URL

时间:2019-06-08 13:41:36

标签: php regex symfony twig

我有这个Facade实体,每次尝试修改包含下面的树枝的表单时,它都会返回此错误:

json

我的控制器操作:

mysql

我的树枝模板

An exception has been thrown during the rendering of a template ("Parameter "buildings_id" for route "addFacade" must match "[^/]++" ("" given) to generate a corresponding URL.").

我试图转储我的/** * @Route("/{id}/card", name="business_card", methods="GET|POST|DELETE", defaults={"business_id"=1}) * @param Request $request * @param Business $business * @return Response */ public function show_card(Request $request, Business $business): Response { $businessCard = $business->getBusinessCard(); $formCard = $this->createForm(BusinessCardType::class, $businessCard); $formCard->handleRequest($request); if (($formCard->isSubmitted() && $formCard->isValid())) { $businessCard = $formCard->getData(); $em = $this->getDoctrine()->getManager(); $em->persist($businessCard); $em->flush(); return $this->redirectToRoute('business_card', ['id' => $business->getId()]); } $dict = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'); return $this->render('business/card.html.twig', ['business' => $business, 'formCard' => $formCard->createView(), 'dict' => $dict]); } 变量,但是数组的所有值都是数字(没有空值)。我还尝试在控制器中为参数{% for buildingsInfo in business.businessCard.buildingsInfos %} {% set idBuildingsInfo = idBuildingsInfo|merge([buildingsInfo.id]) %} <a class="btn btn-outline-primary mb-3" href="{{ path("addFacade",{"buildings_id": idBuildingsInfo[j] }) }}">Ajouter une façade</a> {% endfor %} 添加一个默认值,但是它似乎没有任何改变。

2 个答案:

答案 0 :(得分:0)

仔细阅读错误

  

参数“ buildings_id” ...(已给出“”)

您传递的参数值为空(“”)

Before:

 (1.000000, 0.000000)  (0.500000, 0.000000)  (0.333333, 0.000000)
 (0.250000, 0.000000)  (0.200000, 0.000000)  (0.166667, 0.000000)
 (0.142857, 0.000000)  (0.125000, 0.000000)  (0.111111, 0.000000)
 (0.100000, 0.000000)  (0.090909, 0.000000)  (0.083333, 0.000000)

After:

 (1.000000, 0.000000)  (0.500000, 0.000000)  (0.333333, 0.000000)
 (0.175000, 0.000000)  (0.200000, 0.000000)  (0.125000, 0.000000)
 (0.142857, 0.000000)  (0.125000, -0.000000)  (0.111111, 0.000000)
 (0.175000, 0.000000)  (0.090909, 0.000000)  (0.125000, 0.000000)

是否定义了{{ path("addFacade",{"buildings_id": idBuildingsInfo[j] }) }} 还是该行应如下所示:

j

答案 1 :(得分:-1)

我的猜测是该错误可能与以下情​​况有关:

href="{{ path("addFacade",{"buildings_id": idBuildingsInfo[j] }) }}

也许我们会sethref设置一个变量,然后转义那些需要转义的",我们的代码将如下所示:

{% for buildingsInfo in business.businessCard.buildingsInfos %}
{% set idBuildingsInfo = idBuildingsInfo|merge([buildingsInfo.id]) %}
{% set path = "\"addFacade\", {\"buildings_id\": idBuildingsInfo[j]" %}
<a class="btn btn-outline-primary mb-3" href="{{ path }}">Ajouter une façade</a>
{% endfor %}

或类似。