是否可以使用Form::macro()该Form::model()功能的自定义?
当我第一眼看到它时,我无法将模型数据传递给宏方法.
只有Form :: text之类的Form函数才会自动查找表单模型.在你的宏中,你可以通过几种方式实现.最容易使用Form::getValueAttribute($name).例如:
Form::macro('myField', function() {
$value = Form::getValueAttribute('username');
return "<input type='text' name='username' value=$value >";
});
Run Code Online (Sandbox Code Playgroud)
然后你会在刀片模板中使用它,如下所示:
<?php
$user = new User;
$user->username = "bob";
echo Form::model($user);
echo Form::myField();
echo Form::close();
?>
Run Code Online (Sandbox Code Playgroud)
您可以在源代码中找到所有可用的表单函数:https://github.com/laravel/framework/blob/master/src/Illuminate/Html/FormBuilder.php
| 归档时间: |
|
| 查看次数: |
1607 次 |
| 最近记录: |