1

I have a doubt about doing something or not in order to keep the good practices in Zend Framework.

Lots of times I need to use some functions like: http://www.paulferrett.com/2009/php-camel-case-functions/ or another around the application. The problem is that As i need it on the whole project I can not define as a method of a model, so I tried to use it as helpers.

Now I do not want to use this as helpers because I thing it's not a good practice using view helpers in controllers or models.

I have the following idea: Including a script called functions.php in the index.php of the Zend Application.

What do you think?

1 Answer 1

5

I'm not a fan of putting anything into the global namespace, as you risk a name collision any time you do so. I prefer to put generic utility functions like this in an appropriate class within my application's namespace:

class MyApp_Util
{
    public static function foo()
    {
    }
}

Then you can call with MyApp_Util::foo().

If you've got lots of these types of functions, you can break them down into more appropriate classes:

MyApp_Geo_Util::foo();
MyApp_Math_Util::baz();
MyApp_String_Util::bar();

Or the 5.3 style if you prefer:

\MyApp\Geo\Util::foo();
\MyApp\Math\Util::baz();
\MyApp\String\Util::bar();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.