Zi 字媒體
2017-07-25T20:27:27+00:00
Laravel 中的 Form class 可以協助產生前端表單
基本表單使用
{{ Form::open(array('url' => 'foo/bar', 'method' => 'put')) }}
{{ Form::open(array('action' => 'UsersController@index')) }}
{{ Form::open(array('url' => 'foo/bar', 'files' => true)) }}
{{ Form::close() }}
表單內容操作
{{ Form::open(array('url' => 'foo/bar')) }}
{{ Form::label('name', 'Name:', array('class' => 'address')) }}
{{ Form::text('name', 'Johnson') }}
{{ Form::password('password') }}
{{ Form::submit('Send this form!') }}
{{ Form::close() }}
結合 Model 使用
Controller
class MemberController extends BaseController {
public function getIndex()
{
$member = Member::find('johnsonlu');
return View::make('home', array('member' => $member));
}
}
View
{{ Form::model($member, array('url' => array('home/account', $member->nacid))) }}
{{ Form::label('nacid', 'Account:', array('class' => 'address')) }}
{{ Form::text('nacid') }}
{{ Form::label('name', 'Name:', array('class' => 'address')) }}
{{ Form::text('name') }}
{{ Form::submit('Send this form!') }}
{{ Form::close() }}
Drop-Down Lists
// Default Select(name, array(value => option_str))
echo Form::select('size', array('L' => 'Large', 'S' => 'Small'));
// Default Select
echo Form::select('size', array('L' => 'Large', 'S' => 'Small'), 'S');
// Range
echo Form::selectRange('number', 10, 20);
// Select Month
echo Form::selectMonth('month');
// Group
echo Form::select('animal', array(
'Cats' => array('leopard' => 'Leopard'),
'Dogs' => array('spaniel' => 'Spaniel'),
));
Custom Macros
Form::macro('myInput', function()
{
return '';
});
echo Form::myInput();
Categories: Laravel
分類
Android
AngularJS
API Blueprint
Chrome
Database
MySQL
DataStructure
Docker
Editor
Vim
Firefox
Git
GitLab
Google API
Hadoop
Language
Go
Java
JavaScript
jQuery
jQueryChart
Node.js
Vue
PHP
Laravel
ZendFramework
Python
Mac
Network
Cisco
DLink
Juniper
Oauth
Server
Apache
Share
Unix
FreeBSD
Linux
WebDesign
Bootstrap
CSS
HTML
Wordpress
Search
搜尋關鍵字:
寫了
5860316篇文章,獲得
23313次喜歡