[英]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.