1

I have my own function for making developing easy

Like :

function pr($data,$exit){
    echo "<pre>";
    print_r($data);
    if($exit)
        die;
}



$collection=$this->pincodeCollection->create();
    pr($collection->getData(),1);

Magento2 has helper concept but for helper function use we have to injection helper in the constructor of the class file So I want to avoid this step

In Magento2 any better way where we define our own function. and use everywhere of php code

Your help is appreciated

2 Answers 2

2

In Magento you didn't define any common function like you showing. You have to follow Magento code structure. You have to use the Helper for that.

If you really want this function for temporary use then you can define this function in index.php but never commit this file on the server.

0

One way might be to create a class and add this as a static function. Then you can call the function by calling

\Namespace\of\class::pr($value1, $value2);

Calling static function is considered bad practice and you should never implement it in live production. But for development i guess you can do it if you think it will make your life easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.