way / form
此包已被废弃,不再维护。未建议替代包。
此包的最新版本(dev-master)没有可用的许可证信息。
让 Laravel 中的表单处理更简单。
dev-master
2014-02-28 22:05 UTC
Requires
- php: >=5.4.0
- illuminate/support: ~4
This package is not auto-updated.
Last update: 2018-05-08 13:26:31 UTC
README
基本思想很简单:简化表单创建过程。
我厌倦了创建如表单字段这样的内容
<div class="form-group">
{{ Form::label('username', 'Username:' ) }}
{{ Form::text('username', null, ['class' => 'control-group']) }}
</div>
相反,使用这个 FormField 类,你可以这样做
{{ FormField::username() }}
这将会生成必要的(默认为Bootstrap兼容的)HTML。它使用动态方法简化了过程。
虽然它会尽力推断你想要的输入类型,但你也可以覆盖它。
{{ FormField::yourBio(['type' => 'textarea']) }}
这将生成
<div class='form-group'>
<label for="yourBio">Your Bio: </label>
<textarea class="form-control" type="textarea" name="yourBio" cols="50" rows="10" id="yourBio"></textarea>
</div>
所以,是的,它只是一个辅助类。如果你的表单需要大量的自定义,这个可能不适合你。但对于简单的表单,它做得很好!
(它还使 Laracasts 演示更容易设置。 :)
要尝试此功能
首先通过 Composer 安装包。
require: {
"way/form": "dev-master"
}
然后,将服务提供者添加到 app/config/app.php。
'providers' => [
// ..
'Way\Form\FormServiceProvider'
]
就是这样!你已经准备好了。在视图中尝试一下
{{ FormField::username() }}
{{ FormField::email() }}
{{ FormField::custom(['type' => 'textarea']) }}
{{ FormField::address(['label' => 'Your Address']) }}
这将生成以下内容。虽然默认是Twitter Bootstrap兼容的,但你当然可以根据需要自定义类名。
如果你想覆盖默认设置,可以像这样发布配置
php artisan config:publish way/form
现在,访问 app/config/packages/way/form/config.php 进行自定义。以下是默认列表
return [
/*
* What should each form element be
* wrapped within?
*/
'wrapper' => 'div',
/*
* What class should the wrapper
* element receive?
*/
'wrapperClass' => 'form-group',
/**
* Should form inputs receive a class name?
*/
'inputClass' => 'form-control',
/**
* Frequent input names can map
* to their respective input types.
*
* This way, you may do FormField::description()
* and it'll know to automatically set it as a textarea.
* Otherwise, do FormField::thing(['type' => 'textarea'])
*
*/
'commonInputsLookup' => [
'email' => 'email',
'emailAddress' => 'email',
'description' => 'textarea',
'bio' => 'textarea',
'body' => 'textarea',
'password' => 'password',
'password_confirmation' => 'password'
]
];