By doing this, we would be able to handle multiple versions of our application in a single CodeIgniter installation using the same index file.
There are a couple things we need to setup in order for this to work.
Step 1. Rename Application Folder
Rename your "Application" folder with the first version number you want. You simply rename it with 1.0.0 if its the first version you're creating.Step 2. Rename index.php
Rename your "index.php" file under the root folder with the new Application folder name which is "1.0.0.php". You would also need to replace the line 117 with the following:$application_folder = '1.0.0';
Step 3. Create an index.php file
We now have our first application version. We're not done yet, we need to create an index.php file.<?php define( 'API_VER', 'v' ); array_key_exists( API_VER, $_REQUEST ) ? $v = $_REQUEST[ API_VER ] : $v = '1.0.0'; if ( file_exists( "{$v}.php" ) ) { if ( is_dir( dirname( __FILE__ ) . "/{$v}" ) ) { require dirname( __FILE__ ) . "/{$v}.php"; } else { $error = new stdClass(); $error->error = true; $error->description = 'INVALID_API_VERSION'; echo json_encode( $error ); exit; } } else { $error = new stdClass(); $error->error = true; $error->description = 'INVALID_API_VERSION'; echo json_encode( $error ); exit; }What our index file does is it takes the value of "v" variable then checks the file with the version name if it exists. If it does exists, it loads the corresponding application version, otherwise, it throws an error message. If no version is passed, it simply loads the 1.0.0 version.
To add more application folder, simply duplicate 1.0.0 folder and 1.0.0.php file then rename it with the version number you want. You can now access your application versions by simply adding your version number after your base url.
Ex. "localhost/ci_proj/?v=1.0.0"
I hope you've found this tip useful.
Learn more advanced codeigniter techniques.
Hello World !
ReplyDeleteGood Day !
Keep you services updated & reliable with my stuff
Huge stuff of Tools, E-boooks, Tutorials, Scripting, Viruses, Spying e.t.c
See Me On
I C Q :> 752822040
Tele-Gram :> @killhacks
Many other stuff like
SSN/DL
ID's
CC CVV
DUMPS
Combos/I.P's/Proxies
You can get from my collections :-)
No one TEACH you
No one GUIDE you
No one BOOST you
But I'm always here for you
Hit me up for you desired stuff
I C Q here :> 752822040
Tele-Gram here :> @killhacks
%Waiting for you guys%