Laravel表格方法VS传统编码 [英] Laravel Form methods VS traditional coding

查看:42
本文介绍了Laravel表格方法VS传统编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习Laravel,发现它确实非常有用和有趣.

I am currently learning Laravel and finding it really useful and interesting.

此刻,我正在制作一个简单的在线申请表.

At the moment I am making a simple online application form.

使用Laravel语法进行处理的最大优势是什么:

What are the biggest advantages to doing things using the Laravel syntax like:

{{ Form::open(array('url' => 'foo/bar')) }}

与简单地相反:

<form action="foo/bar">

或者:

echo Form::text('username');

代替:

<input type="text" name="username" />

Laravel方法必须更好,我只是想知道为什么?

The Laravel way must be better, I just wish to know why exactly?

推荐答案

使用内置HTML帮助器有很多好处:

Using built-in HTML helpers have many benefits:

  1. 使用Form::open将CSRF保护输入添加为隐藏(默认情况下)

  1. Using Form::open you add CSRF protection input hidden (by default)

使用表单元素(输入/文本区域等)和withInput重定向方法可让您轻松地用几乎没有编码的相同数据填充表单

Using form elements (inputs/textarea etc.) and withInput method for Redirection allows you to easily fill in the form with the same data with almost no coding

如果您使用Redirect::route('form'->withInput();并输入了 文本{{Form::text('username')}}它将自动设置输入值的旧数据-您无需自己检查就可以对其进行编码

If you use Redirect::route('form'->withInput(); and have input text {{Form::text('username')}} it will automatically set input's value the old data - you don't need to code it yourself checking it

如果您想将带有标签的字段匹配起来也很容易:

Also if you want to match fields with labels its much easier:

{{ Form::label('username', 'Enter username') }}
{{ Form::text('username') }}

它将生成以下代码:

<label for="username">Enter username</label>
<input name="username" type="text" id="username">

如您所见,ID将自动创建

so as you see id will be created automatically

可能还有更多.但是,主要的缺点是您需要学习,并且如果希望将站点移至其他Framework,但是每种解决方案都有其优缺点,则它不是可移植的.

Probably there are some more. However the main disadvantage is that you need to learn and it's not portable in case you want to move your site to other Framework but each solution has pros and cons.

这篇关于Laravel表格方法VS传统编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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