2016-11-25 50 views
0

定制表单辅助如何在CakePHP 3.X中重载FormHelper?每次我需要

<?php  
namespace App\View\Helper;  
use Cake\View\Helper; 

class IecFormHelper extends Helper 
{ 
    public $helpers = ['Form']; 
    public $iecFormConfig = [   
     'templates' => [    
      'input' => '<input type="{{type}}" name="{{name}}"{{attrs}} onBlur=update_data(this.id) />', 
     ] 
    ]; 

    public function date($fieldName, array $options = []) 
    { 
     $options += [ 
      'empty' => true, 
      'value' => null, 
      'monthNames' => true, 
      'minYear' => 1950, 
      'maxYear' => date('Y') + 50, 
      'orderYear' => 'desc', 
     ]; 
     $options['hour'] = $options['minute'] = false; 
     $options['meridian'] = $options['second'] = false; 

     $options = $this->_initInputField($fieldName, $options); 
     $options = $this->_datetimeOptions($options); 

     return $this->widget('datetime', $options); 
    } 
} 

我有“的src /查看/助手”,它基本上是有来调用模糊javascript函数模板规则的,也是我想改变下这个助手类所有日期下拉列表中的minYear和maxYear值。

我的问题是如何以及在哪里使用这个助手,以便它覆盖主FormHelper中的规则。

回答

1

您只需加载并使用你的助手,而不是形式的帮手。
如果你想覆盖Formhelper你应该扩展FormHelper在你的IecFormHelper