Using a functions script in Zend framework

孤街浪徒 提交于 2019-12-11 10:27:20

问题


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:


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();


来源:https://stackoverflow.com/questions/8299396/using-a-functions-script-in-zend-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!