Zendframework 2 : how to define global custom functions easily

Hello Friends,

As we know that zendframework 2 is not very easy to learn or understand.  Its true that its 100% pure OOPS. But for beginner it may create problem to understand it. It is not easy compare to ZF1 (Zendframework 1) initially. Zendframework 1 work was easy to understand, but now in zendframework2 it is completely different acrchitecture.  Now load speed is minimized in zendframework 2. But problem for beginner is to implement code.  I am also learning zendframework 2 and founded that it sometimes take more time to code. I

Custom functions

Suppose if you want to use your own custom functions then it is required to updated module.php and other files.    But i have an other short cut using which you can use your own functions very easily. And also you will not required to write anything in module.php, controller or module file. Even you dont need to use namespace or  dont need to use php function ‘Use’ .

Steps to create custom functions in zendframework 2

Step-1 : Just create one file say myfunctions.global.php in  autoload directly. and write your function in normal way

Step -2: At last in this file, you just need to write blank array like following.

Example :


function plus($v1,$v2)

return $v1+$v2;


return array();      // dont forget to write this

That’s it.

Now you just use function name in your model, controller or module in simple way like you were used in core coding. I know that perhaps this is not write way. But to do some task, i think this is very short cut.

Am i right ?