PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 15, 2022

[FIXED] How can I override FormHelper in CakePHP 3.X?

 February 15, 2022     cakephp, cakephp-3.0     No comments   

Issue

Customised form helper per my need

<?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);
    }
}

I have this helper class under "src/View/Helper" which basically have template rule for to call javascript function on blur, and also I want to change the minYear and maxYear values for all date dropdown.

My question is how and where do I use this helper so that it overrides rules in the main FormHelper.


Solution

You can just load it and use your Helper instead of form helper.
If you want to overwrite Formhelper you should extend FormHelper in your IecFormHelper



Answered By - Tolga
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing