[eluser]John_Betong[/eluser]
Hi All,
Preamble
Delphi has a wonderful technique that allows the programmer to easily switch
between applications by using a menu system.
CodeIgniter's rigidity and hard-coding has been bothering me for quite some time
as to the easist way to achieve:
1. easily switch CodeIgniter applications
2. use a common codeIgniter System folder.
I used to manually edit my "index.php" file but now with a slight modification
to the file I can now select the application from "_menu.php".
Usage
I have the following application directories setup: each directory is copied
from CodeIgniter's system/application folder.
My Localhost directory structure
Code:
...
ci_bandwidthmeter
ci_betsprint
ci_fred
ci_jokes
ci_plaroma
ci_rentaroofbox
ci_system // renamed CodeIgniter's "system" folder for consistency
...
index.php // modified
_menu.php //
The index.php was slightly modified so that instead of having
"$application_folder" hard-coded it now reads from an "_application.php" file.
I wrote a "_menu.php" file that generates the "_application.php" file.
index.php
Code:
...
...
// old code that had to be manually edited to select different applications
// the required application was copied and pasted to be the last declaration
$application_folder = 'ci_bandwidthmeter';
$application_folder = 'ci_betsprint';
$application_folder = 'ci_fred';
$application_folder = 'ci_jokes';
$application_folder = 'ci_plaroma';
$application_folder = 'ci_rentaroofbox';
// new _menu.php driven setting
include('_application.php'); // contents generated from "_menu.php"
$application_folder = APPLICATION_FOLDER; // included contents from "_application.php" file
...
...
_menu.php
Code:
<?php
// file name to save CodeIgniter's $application_folder variable
$filename = getcwd() .'/_application.php';
// delete file that holds the $application_folder variable if and only if it exists
if (file_exists($filename)) {
unlink($filename);
}
// check to see if a $application has been passed at the command line
$application = isset($_GET['application']) ? $_GET['application'] : ''; // '$application is NOT set' ;
// write the $application variable to the $filename file
if ($application) {
$application = "<?php define('APPLICATION_FOLDER', $application) ?>";
$saved = file_put_contents($filename, $application);
if ($saved) {
header("Location: index.php"); /* Redirect browser */
exit;
}else{
// echo 'Message goes here ==> '. $filename;
}
}//endif $application
// optional to eliminate html errors
if (file_exists('_head.php')) {
include('_head.php');
}else{
echo '<html><title>My CodeIgiter menu</title></head>';
}
// fall through to menu selections using radio buttons
?>
<body style='background:#f00 none; color:#00f'>
<div style='width:40%; margin:4em auto; background:#fff none; color:#000; border:outset 6px; padding:1em'>
<form action='_menu.php' style='font-size:1.4em'>
<dl>
<dt style='color:#f00'>My CodeIgniter Applications<br /><br /></dt>
<?php
$b = array(
/* 'system/application', */
/* 'plaroma-web-vhost/40c074f1c862da07d2a392dfdd89dd23',*/
'ci_bandwidthmeter',
'ci_betsprint',
'ci_fred',
'ci_jokes',
'ci_plaroma',
'ci_rentaroofbox'
);
$ddstart = "<dd><input type='radio' name='application' value='" ; // ."' />" ;
foreach($b as $row):
echo $ddstart . $row ."' />$row</dd>";
endforeach;
?>
<dt>
<br />
<input type="submit" value=" Continue " class='button' />
<br />
</dt>
</dl>
</form>
</div>
</body>
</html>
I am curious to know if anyone else has done something similar?
Cheers,
John_Betong