Codeigniter 我的辅助函数
首先,很抱歉,如果这是一个愚蠢的问题,但我是初学者,我想听听更有经验的开发人员的意见。
我正在使用 codeigniter 构建一个房地产网站,并且我有城市名称,这些字符是重音字符,但由于搜索和其他验证,我在数据库中发送这些非重音字符。
因此,当我选择这些字符时,它们是非重音字符,我创建了一个帮助器来将这些字符转换为后重音字符。
我的问题是,如果我在我看来运行这个助手可以吗?
我的意思是,助手是自动加载的,因为我需要在 4 个视图文件中使用它,并且我在视图中像这样调用它的函数,
echo city_accent($e->city);
所以如果我在视图文件中像这样运行它,会出现问题吗?
谢谢
first of all sorry if its a stupid question but I'm a beginner, and I would like the opinion of a more experienced developer.
I'm building a real estate site with codeigniter, and I have city names what are accented characters, but I'm sending these in the database non accent because of the search, and because of the other validations.
So when I select these they are non accented chars, I created a helper what converts these back accented.
My question is, is it ok if I run this helper in my view?
I mean like, the helper is auto-loaded because I will need this in 4 view files, and I call its function like this in the view
echo city_accent($e->city);
so is it a problem if I run it like this in my view file?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以在视图中调用辅助函数,但根据约定更好的方法是在控制器中调用它并将其传递给视图表单控制器。
喜欢:
希望有帮助
Calling a helper function in view can be done, but better way as per the convention would be to call it in controller and pass it to view form controller.
like:
Hope it helps
从技术上讲,你可以做到这一点。只要该助手加载到调用视图的控制器中即可。
不过我不会把它放在视图中。在MVC环境中布局和逻辑需要分离。我将在控制器中使用 city_accent() 函数,并通过参数将结果传递到视图中。
Technically, you can do that. As long as that helper is loaded in the Controller that calls the View.
I wouldn't put it in the View however. Layout and logic need to be separated in an MVC environment. I would use the city_accent() function in my Controller and pass the result into the View by parameter.