简体   繁体   English

对多个 codeigniter 项目使用相同的配置文件

[英]Using same config files for multiple codeigniter projects

I'm setting up a project where i wish to use the same codeigniter system + share some common models, libraries and even config files between the different websites.我正在建立一个项目,我希望在其中使用相同的 codeigniter 系统 + 在不同网站之间共享一些通用模型、库甚至配置文件。

I have put my system folder and a shrunk in application folder in docs/include/codeigniter and i define the path for the system folder in the index file of every website.我已经将我的系统文件夹和一个缩小的应用程序文件夹放在 docs/include/codeigniter 中,我在每个网站的索引文件中定义了系统文件夹的路径。 I figure, that in order to use the models, libraries and config files from this application folder, i should use the add_package_path() function from https://www.codeigniter.com/userguide3/libraries/loader.html我想,为了使用这个应用程序文件夹中的模型、库和配置文件,我应该使用https://www.codeigniter.com/userguide3/libraries/loader.html 中的 add_package_path() 函数

But where can i put this call to make sure that it loads as early as possible?但是我可以把这个调用放在哪里以确保它尽可能早地加载? I would like to be able to even share the autoload.php config file, but if i call this method in the constructor of the index controller i will receive an error, because CI needs to use some of the config files before starting to load controllers.我什至希望能够共享 autoload.php 配置文件,但是如果我在索引控制器的构造函数中调用此方法,我将收到一个错误,因为 CI 需要在开始加载控制器之前使用一些配置文件.

I don't know the solution using add_package_path() , but this could work:我不知道使用add_package_path()的解决方案,但这可以工作:

Configuration配置

Firstly, check out application/config/autoload.php for $autoload['config'] .首先,查看application/config/autoload.php$autoload['config']

If it for some reason does not suit your purposes: The CodeIgniter config files are also just PHP files.如果由于某种原因不适合您的目的:CodeIgniter 配置文件也只是 PHP 文件。 So you can make your own common_config.php file and then just use require '../some_common_folder/common_config.php';所以你可以制作自己的common_config.php文件,然后使用require '../some_common_folder/common_config.php'; in the configuration files of your CodeIgniter projects.在 CodeIgniter 项目的配置文件中。

Models楷模

Again, see application/config/autoload.php for $autoload['model'] .同样,请参阅application/config/autoload.php以了解$autoload['model']

You can also define your own function __autoload($classname) {} in the index.php file of each of your CodeIgniter projects, where you can load/require/include whatever you want.您还可以在每个 CodeIgniter 项目的index.php文件中定义您自己的function __autoload($classname) {} ,您可以在其中加载/要求/包含您想要的任何内容。

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

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