Search code examples
zend-frameworkzend-studio

How to define own functions in zend framework


Actually I wanted to know that is there any way to define and call a function in Zend framework which does not need to put with $this like pr() function in cake php. I want to define a such a function which can be called directly in all controllers and views in zend framework. Can it be done by putting all functions in helper and use them without writing $this in front of them.

For example I wanted to make a function arrprint() to print the array in helper and use it globally with only by writing simply arrprint();

Please help me


Solution

  • You could just create a file anywhere and put the function in there. The just include it like you would any other files.

    Or create a library called Utils and put your custom functions there as static and call them using:

    Utils::myFunction();
    

    Contrary to cake zf does not enforce much anything. You can leverage the framework to do whatever you want.

    BTW $this is just a pointer to the current class and when you use $this->myFunction(); it's because that function is a member of the current class (or its parent).