Laravel 4刀片格式格式化(隐藏输入) [英] Laravel 4 Blade Form Formatting (Hidden Input)

查看:77
本文介绍了Laravel 4刀片格式格式化(隐藏输入)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个艺术家"资源,在表演路线页面上,我有一个表格.我正在使用Laravel Blade语法.作为此表单的一部分,我试图将页面ID发送到Laravel 4项目的后端.我这样做是这样的:

I have an "artist" resource, and on the show route page I have a form. I am using Laravel Blade syntax. As part of this form, I am trying to send the page ID to the back end of a Laravel 4 project. I am doing it this way:

{{Form::hidden('artist-id',null, array(
'id' => '{{$artist->id}}',
));}}

但是,使用此方法时,浏览器将引发错误,因为它未在输入表单的外部括号之前的括号内呈现$ artist-> id变量.

However, when using this, the browser throws an error, because it is not rendering the $artist->id variable within the brackets before the outside brackets of the input form.

是否有解决此问题的方法或为资源传回此变量的另一种方法?谢谢!

Is there a way around this or another way to pass back this variable for the resource? Thank you!

推荐答案

因此,刀片标记{{ }}中的所有内容均被视为标准PHP.在现有刀片标记中进一步使用{{ }}只会引发很大的错误.

So anything inside the blade tags {{ }} is treated as standard PHP. Using further {{ }} inside existing blade tags is just going to throw a big error.

由于blade标签内的所有内容均被视为PHP,因此您只需执行以下操作

Because anything inside the blade tags is treated as PHP you can simply do the following

{{ Form::hidden('artist-id', null, ['id' => $artist->id]) }}

尽管发布该输入并不会为您提供所需的值,因为提供的值是null. id属性是赋予html属性的html ID.您需要执行以下操作来设置输入值,然后将其与表单数据一起发布

Although posting that input isn't going to give you the value you want, because the value supplied is null. The id attribute is the html ID given to the html attribute. You need the following to set the value on the input, which will then be posted in with your form data

{{ Form::hidden('artist-id', $artist->id) }}

这篇关于Laravel 4刀片格式格式化(隐藏输入)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆