Welcome Guest, Not a member yet? Register   Sign In
Comparing $indexPage in IncomingRequest for multi-app setup
#1

(This post was last modified: 01-26-2021, 12:14 PM by xbotkaj.)

Hi guys, I just bumped to something I need to have nice a way how to handle mutiple applications using single CI core.

My setup:

Code:
- /apps
   - /app1
    - /Config
  - /app2
    - /Config
- /common
   - /Config
- /system
- /public
  - index.php (defualt front controller)
  - app2.php (second app front controller)
  - .htaccess


I would like to use URL like "http://localhost/app2" and it should be directed to app2.php to properly run application and initialize app2.

For this purpose I use mod_rewrite:
Code:
    # Convert first segment to front controller if exists
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^([^.*\/]*).*$
    RewriteCond %{DOCUMENT_ROOT}/%1 -f
    RewriteRule ^([^.*\/]*)(\/.*).*$ $1.php$2 [L,NC,QSA]
    RewriteRule ^([^.*\/]*)$ $1.php [L,NC,QSA]

After that I set indexPage for each app in this case $indexPage = 'index.php' and $indexPage = 'app2.php'

Now we need just add hook to IncomingRequest class to parseRequestURI method like this -> when checking for segments
Code:
// or when first segment is equal to indexPage
elseif (strpos(trim($uri,'/'), $this->config->indexPage) === 0)
{
   $uri = (string) substr(trim($uri,'/'), strlen($this->config->indexPage));
}

What do you think ? Smile

THX
Reply


Messages In This Thread
Comparing $indexPage in IncomingRequest for multi-app setup - by xbotkaj - 01-25-2021, 12:05 PM



Theme © iAndrew 2016 - Forum software by © MyBB