How to have shared libraries and helpers between applications in CodeIgniter 3 |
Assume the following situation:
- 2 applications using 1 CodeIgniter installation under the same URL - The requirement to share libraries and helpers (and maybe more) between application - and...reduce redundant code PS. change the server names below to your own situation! Code: - CodeIgniter-3.1.10 <- framework, don't change anything here How to do it? In the index.php of both servers (not the common one): Code: // $system_path = "system"; In the autoload.php of both servers you add the following: Code: $autoload['packages'] = [dirname(__FILE__, 4) .'/server_common']; Sample of a common library "Itworks.php" in folder "libraries" of "server_common": Code: <?php Sample of a controller calling the "show" function in either of the other servers: Code: <?php As you can see, once loaded it works like a normal library. And, you can still load the local libraries on the server too. Now use in your browser: Code: https://www.yourserver.com/server_other/valhalla/itworks |
Welcome Guest, Not a member yet? Register Sign In |