简体   繁体   中英

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 :

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). I also tried to add a default value in my controller for parameter buildings_id but it does not seem to change anything.

Read the error carefully

Parameter "buildings_id" ... ("" given)

The parameter value you passed is null ("")

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

Is j defined? 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM