简体   繁体   English

如何在 CodeIgniter 的每个页面上都有一个被调用的控制器

[英]How to have a called controller on every page in CodeIgniter

I want to have a controller to do some initial settings and fetch some basic data in all of my application pages (written with PHP and CodeIgniter).我想要一个控制器来做一些初始设置并在我的所有应用程序页面(用 PHP 和 CodeIgniter 编写)中获取一些基本数据。 As I'm new in CI, please help me to do it.由于我是 CI 的新手,请帮助我做到这一点。
Some of my goals to have such controller:我拥有这样的控制器的一些目标:

  1. Setup submenus (regardless of the current page)设置子菜单(与当前页面无关)
  2. Check user login status.检查用户登录状态。

Notice:注意:

I don't have any problem on creating and working with general Controllers in CI.我在 CI 中创建和使用通用控制器没有任何问题。 What I need is something like a hidden controller that does not any need to URI segments to run, and it is not the CI default controller too.我需要的是一个隐藏的控制器,它不需要运行 URI 段,而且它也不是 CI 默认控制器。

What you can do is create a base controller and and extend that base controller in every other controllers instead of CI_Controller .您可以做的是创建一个基本控制器,并在所有其他控制器而不是CI_Controller扩展该基本控制器。 Your base controller will extend CI_Controller .您的基本控制器将扩展CI_Controller You can add your required checks in the constructor of the base controller and do stuffs according to that.您可以在基本控制器的构造函数中添加所需的检查,并根据该检查进行操作。 So every time you call a controller your checks will be done.因此,每次您调用控制器时,您的检查都会完成。 But you have autoload the base controller.但是您已经自动加载了基本控制器。 I hope this helps you.我希望这可以帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM