Codeigniter 中的可重用函数

发布于 2024-09-07 13:53:16 字数 194 浏览 2 评论 0原文

几乎在我的大多数控制器的所有功能中,我都必须注意相同的事情。 IE

1.检查是否登录。 2.检查权限。

我知道该怎么做。但是最好的方法是什么,这样我就不必重新编写相同的内容 代码无处不在?是为了做一个帮手还是什么?我对 codeigniter 有点陌生,我只知道基本的 php!

Almost in all function in most of my controller i have to see to same things. i.e

1.Check if logged in.
2.Check the privilege.

I know how to do it. But what is the best way, so that i don't have to re-write the same
code everywhere? Is it to make a helper or something? I'm a bit new to codeigniter, all i know is basic php!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苦行僧 2024-09-14 13:53:16

如果控制器中的所有方法都需要相同的代码,您可以将该验证代码放在构造函数中。

否则,创建一个助手可能是最好的方法,但您仍然需要在每个需要验证的方法中重复该函数。

If all the methods in your controller need the same code, you can put that authentification code in the constructor.

Otherwise, creating a helper is probably the best way, but you'll still have to repeat the function in each method subject to authentification.

不回头走下去 2024-09-14 13:53:16

您可能会发现这些链接很有用:

什么 Code Igniter 身份验证库最好?
使用 CodeIgniter 进行身份验证

您可能想要实际创建如果需要的话,用于用户处理的辅助类以避免重复的代码。

You may find these links useful:

What Code Igniter authentication library is best?
Authentication with CodeIgniter

You might want to actually create a helper class for user handling to avoid repetitive code if you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文