php - 带有href的视图上的按钮在路由中传递了一个变量?
问题描述
我想要一个按钮的 url 把它带到一个在 URL 中有 ID 的页面。
控制器:
public function printpreviewingredients($MealPlan_ID)
{
//contains the value
$ingredientsid = $MealPlan_ID;
return view('MealPlanDisplay.printpreviewingredientslist', compact('ingredientsid'));
带有 URL 的按钮:
<div class="d-flex justify-content-end mb-4">
<a class="btn btn-primary" href="{{ url('/printpreviewingredients/pdf/$ingredientsid') }}">Export to PDF</a>
</div>
尽管 $ingredientsid 的值不是空白,但它仍然不会将该值放在 URL 链接中。如何将 Controller 方法中的变量传递到按钮 url?我可以让它在带有@foreach 循环的表中工作,但从演示角度来看,它看起来不正确。
解决方案
您必须连接变量,不要在单引号内使用 PHP。当您使用单引号时,其中的所有内容都被视为字符串,即使您使用 PHP 语法也是如此。
利用:
href="{{ url('/printpreviewingredients/pdf/'.$ingredientsid) }}"
代替:
href="{{ url('/printpreviewingredients/pdf/$ingredientsid') }}"
推荐阅读
- visual-studio - 如何确认 Eigen 在 Visual Studios 中启用矢量化?如何检查是否定义了 EIGEN_VECTORIZE 预处理器符号?
- html - 折叠表格行而不是单元格时是否存在已知问题?
- python - Python 3:使用 Exec 赋值
- javascript - 将鼠标滚轮滚动添加到 Konva JS Stage,并在最外层对象的开始和结束处使用 Anchor
- typescript - 监听模型值变化并计算
- powershell - 我可以在 Powershell 中打开无缓冲程序输出吗?
- angular - 始终自动登录 Microsoft 帐户
- spring-boot - Spring Boot 最佳实践
- html5-canvas - FabricJS:如何自动调整图像大小以适合组或矩形对象?
- php - 无法将 JSON 数据源添加到 refl.me