After head-banging 100 times, I decided to change my directory structure and right now, everything is working great. :) I am posting this answer to help others who alos have faced the same problem. So here's, my Directory Structure.
- WebRoot /
- AppName /
- v0.2 /
- v0.5 /
- v0.9 /
- _APP /
- cache /
- data /
- libs /
- vendor /
- Slim /
- userCake /
- MeekroDB /
- Acc / ( Seperate Routes )
- API /
- .htaccess
- index.php
- Assets /
- images /
- css /
- js /
- fonts /
- Test /
- .htaccess
- 404.php
- config.php
- index.php
- _APP /
- AppName /
Now, these are the codes I use inside the main files: index.php under API contains Slim Routes.
.htaccess under APi contains the following code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA]
</IfModule>
index.php under v0.9 directory contains the homepage
.htaccess under he same directory contains:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
RewriteRule ^(_APP/) - [F,L,NC]
</IfModule>
This .htaccess restricts direct access to _APP folder as it contains sensitive data. Now people will tell me to move it outside the publicly accessible directory but for users with shared hosting like me, the hosting company restricts going outside the public root. Although using this setup secures the App But you should always try to move this _APP directory outside public directory.
and the main config.php contains:
<?php
// PROJECT SETTINGS
// Show Erros on Localhost and Local Ethernet only
$test_server = $_SERVER['SERVER_NAME'] == "127.0.0.1" || $_SERVER['SERVER_NAME'] == "localhost" || substr($_SERVER['SERVER_NAME'],0,3) == "192";
ini_set('display_errors',$test_server);
error_reporting(E_ALL|E_STRICT);
$_APP=array();
// META CONFIGURATIONS
$_APP= array_merge($_APP, array(
'meta'=>array(
'name'=>'expoWWW',
'ver'=>'v 0.0.2',
'url'=>'http://localhost/AppName/v0.9/',
'root'=>$_SERVER['DOCUMENT_ROOT'].'/',
'appUrl'=>'AppName/v0.9/',
'author'=>'Abhishek Deb (iam@debabhishek.com)',
'admin'=>''
)
));
// DATABASE CONFIGURATION
$_APP= array_merge($_APP, array(
'db'=>array(
'h'=>'localhost',
'u'=>'root',
'p'=>'root',
'd'=>'APpName'
)
));
// FUNCTIONS
// HOUSE-KEEPING
?>
Usage: I simply Include this config file in every php file and then I can use $_APP['db']['h']