简体   繁体   English

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

[英]Parameter “” for route “” must match “[^/]++” (“” given) to generate a corresponding URL

I have this Facade entity, everytime I try to modify a form where my below twig is included, it returns this error : 我有这个Facade实体,每次尝试修改包含以下细枝的表单时,都会返回此错误:

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.").

My controller action : 我的控制器动作:

/**
 * @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]);
}

My twig template : 我的树枝模板:

{% 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 %}

I tried to dump my idBuildingsInfo variable, but all values of the array are numbers (no null values). 我试图转储idBuildingsInfo变量,但是数组的所有值都是数字(无null值)。 I also tried to add a default value in my controller for parameter buildings_id but it does not seem to change anything. 我还尝试在控制器中为参数buildings_id添加一个默认值,但是它似乎没有任何改变。

Read the error carefully 仔细阅读错误

Parameter "buildings_id" ... ("" given) 参数“ buildings_id” ...(给出“”)

The parameter value you passed is null ("") 您传递的参数值为空(“”)

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

Is j defined? 是否定义了j or should that line look like this: 或者该行应如下所示:

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

My guess is that the error might be pertinent to: 我的猜测是该错误可能与以下方面有关:

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

and maybe we would set a variable for our href , and then escape those " s that are require to escape, and our code would look like: 也许我们会set一个变量为我们的href ,然后逃离那些" S中的需要逃避,我们的代码将如下所示:

{% 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 %}

or somewhat similar. 或有点相似。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Symfony2 允许空路由参数“必须匹配 ^/ ++(给定)以生成相应的 url” - Symfony2 allow empty route parameter “must match ^/ ++ ( given) to generate a corresponding url” Symfony2“参数”“用于路由”“必须匹配”[^ /] ++“(”“给定)以生成相应的URL。” - Symfony2 “Parameter ”“ for route ”“ must match ”[^/]++“ (”“ given) to generate a corresponding URL.” Symfony generateUrl 问题 .... 必须匹配 &quot;[^/]++&quot; (&quot;my string with special chars&quot; given) 以生成相应的 URL。 - Symfony generatUrl problem .... must match "[^/]++" ("my string with special chars" given) to generate a corresponding URL." Symfony2路由错误(参数 <x> 路线 <r> 必须匹配 <pattern> ) - Symfony2 routing error (parameter <x> for route <r> must match <pattern>) 在渲染模板期间抛出异常(路由“delete_User”的“参数”salt“必须匹配”[^/]++“ - An exception has been thrown during the rendering of a template (“Parameter ”salt“ for route ”delete_User“ must match ”[^/]++" “无法为指定路由生成URL - "Unable to generate a URL for the named route 使用Silex的app.url_generator.generate将路由参数传递到Twig模板 - Passing route parameter to Twig template using Silex's app.url_generator.generate 无法为命名路由生成URL - Unable to generate URL for named route URL的路由参数的正则表达式 - regular expression for route parameter of URL URL GET Route Laravel 中的参数 - URL Parameter in GET Route Laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM