开发者

Can't avoid field label to be echoed

I've been creating an app preparing it already to be internationalized. But when I try to do this:

echo $this->Form->input('end_date', array('label' => __('End Date'), 'dateFormat' => 'DMY', 'minYear' => date('Y'), 'type' => 'text'));\

It echoes two "End Date". I tried disabling lab开发者_StackOverflow中文版el by setting it to null, but didn't work either. :(

How can I avoid this to happen?

Thanks


Instead of NULL, try setting it to false:

'label' => false

You can also set ALL inputs of a form to default to 'label'=>false by using:

'inputDefaults'=> array('label'=>false)

as an option of your form


For what it's worth, the __() function echoes its value by default instead of returning it. That's why you were seeing the label displayed twice. It was being displayed once because that's the value that the field name resolves to automagically. It was being displayed the second time by the __() method. In other words, your label option wasn't really overriding the automatic label.

echo $this->Form->input(
  'end_date', 
  array(
    'label' => __('Modified End Date Label', true), # note the "true" argument
    'dateFormat' => 'DMY', 
    'minYear' => date('Y'), 
    'type' => 'text'
  )
);

For more, see the __ documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜