在 CakePHP 中,是否可以全局设置传递给表单助手创建方法的选项?
在 CakePHP 中,是否可以全局设置传递给表单助手创建方法的选项?
由于我希望在所有表单上使用特定的表单布局,因此我当前在创建每个表单时都必须执行此操作。
<?php
echo $this->Form->create('User', array(
'class' => 'form-horizontal',
'inputDefaults' => array(
'format' => array('before', 'label', 'between', 'input', 'error', 'after'),
'between' => '<div class="controls">',
'after' => '</div>',
'div' => 'control-group',
'error' => array(
'attributes' => array('wrap' => 'span', 'class' => 'help-inline')
)
)
));
?>
我想知道是否有一种方法可以在全局范围内指定这一点,这样我就不需要在每次创建调用时都这样做。
In CakePHP is it possible to set the options you pass to the Form helper create method globally?
Since I want a specific form layout to be used on all my forms I am currently having to do this when I create every form.
<?php
echo $this->Form->create('User', array(
'class' => 'form-horizontal',
'inputDefaults' => array(
'format' => array('before', 'label', 'between', 'input', 'error', 'after'),
'between' => '<div class="controls">',
'after' => '</div>',
'div' => 'control-group',
'error' => array(
'attributes' => array('wrap' => 'span', 'class' => 'help-inline')
)
)
));
?>
I was wondering if there was a way to specifiy this globally so I didn't need do it with every create call.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在某处进行配置(即:
app/config/core.php
——或者如果您扩展了配置系统,则使用类似的包含文件)使用它看起来像这样...
如果您需要获取对于某些特殊形式更具体......
Make a configuration somewhere (ie:
app/config/core.php
-- or a similarly included file if you've expanded your configuration system)Using it looks like this...
If you need to get more specific for certain special forms...
starlocke的答案是好的,但我什至不想把这三行写得到处都是。 :) 我也不认为这真的是“配置数据”。所以这就是我要做的:
然后简单地调用它:
$this->MyForm->create('Profile');
或者在您想要更改某处的第二个参数中使用单个选项来调用它。
The answer of starlocke is ok but I would not even want to write these three lines all over the place. :) Neither I think this is really "config data". So here is what I would do:
Then simply call it:
$this->MyForm->create('Profile');
or call it with a single option in the 2nd param you want to change somewhere.