Welcome Guest, Not a member yet? Register   Sign In
Class alias and changing helpers
#1

I suggest considering the possibility of setting up class aliases and replacing the helpers from functions with class methods.
This will simplify the use of helpers and allow them to be extended.
Example
PHP Code:
//Autoload config

$alias = [
    'Html' => \CodeIgniter\Helpers\Html::class,
    'Arr' => \CodeIgniter\Helpers\Array::class,
];

// Html class

class Html 
{
    public static function anchor()
    {
        return '....';
    }

    public static function link()
    {
        return '....';
    }    
}

// using  

Html::anchor();


// extends 

$alias = [
    'Html' => \App\Helpers\Html::class,
];

// Html class

class Html extends \CodeIgniter\Helpers\Html 
{
    public static function anchor()
    {
        return '....';
    }

  • Direct use in templates without preloading via the helper() function
  • Using protected methods instead of prefixed functions. Like _some_protected_function()
  • Resolving possible conflicts in the names of functions of external libraries.
Reply
#2

I have to agree on this also, would make it a lot simpler to use and maintain.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB