开发者

ZF: Where to put custom function

开发者 https://www.devze.com 2023-02-19 01:03 出处:网络
I have an enCrypt and deCrypt class which I want to use in my whole Zend Framework project without having to declare it on every need, but j开发者_运维知识库ust once. Where should this be done? Thank

I have an enCrypt and deCrypt class which I want to use in my whole Zend Framework project without having to declare it on every need, but j开发者_运维知识库ust once. Where should this be done? Thank you for any help...


Zend Framework is quite flexible in implementing things.

You could create an instance in a bootstrap file and save it to the registry; whenever you need to call the class just get it from registry?

You could have every controller extend Zend_Controller_Action and put the two functions into this class (only ideal if you're calling the classes from the controller).

Or, what I did, was make my functions static, register my own library (in your application config.ini file, enter the line: autoloaderNamespaces[] = "MyPrefix_", then create a folder in the library folder called MyPrefix) and drop my class in there. When I need it I call $encryptedString = MyPrefix_Crypt::encrypt($string); and $string = MyPrefix_Crypt::decrypt($encryptedString);

Hope this helps :)

0

精彩评论

暂无评论...
验证码 换一张
取 消