问题描述
我在我的一个视图中有一个函数,用于在显示之前格式化来自数据库的数据。由于我在许多视图中使用这个函数,我想创建一个可以从每个视图访问的全局函数。
I have a function in one of my views that formats data coming from the DB before displaying it. Since I use this function in many views, I'd like to make a global function that would be accessible from every view. How would I do that ?
推荐答案
如其他答案所述,创建助手可能是您正在寻找的。有关详情,请参阅。
As mentioned in the other answers, creating a helper is probably what you are looking for. See the cookbook entry for more information.
要在所有视图中使用帮助程序,请将帮助程序添加到 AppController
的 $ helpers
( app / Controller / AppController.php
)。
To make your helper available in all your views, add the helper to the $helpers
array of your AppController
(app/Controller/AppController.php
).
这篇关于在CakePHP中放置自定义函数的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!