added ROOTPATH constant #1270

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
5 participants
Contributor

davidbehler commented Apr 20, 2012

ROOTPATH points to the folder where the system folder resides in. Ff you use the standard setup, then it's the same as FCPATH, but if you use a different setup, e.g. system and application folder are one level above index.php (to hide them from public access), then you can use ROOTPATH instead of FCPATH to address the folder that holds system and application. I use this in CI 2.1.x projects where I have a common folder next to system and application that holds libraries/packages that are shared between multiple apps.

Example:

require_once(ROOTPATH.'common/libraries/Some_lib.php');
David Behler added ROOTPATH constant
ROOTPATH points to the folder where the system folder resides in, if you use the standard setup, then it's the same as FCPATH, but if you use a different setup, e.g. system and application folder are one level above index.php (to hide them from public access), then you can use ROOTPATH instead of FCPATH. I use this in CI 2.1.x projects where I have a common folder next to system and application that holds libraries/packages that are shared between multiple apps.
f631038
Contributor

timw4mail commented Apr 20, 2012

That's what the BASEPATH constant is for.

Defining the application path as a relative directory works fine, so I don't personally seen the usefulness of adding another constant.

Contributor

davidbehler commented Apr 20, 2012

BASEPATH points to the system directory and that's not what I need. Imagine this folder setup

--somefolder (/home/user/somefolder/)
--| admin_application
--| application
--| common
--| system
--| public_html
----| assets
------| images
------| css
----| index.php

The constants will have these values:
BASEPATH: /home/user/somefolder/system/
FCPATH: /home/user/somefolder/public_html/
SYSDIR: system
ROOTPATH: /home/user/somefolder

Now let's say you have a file called Base_Controller.php in common/core and want to extend it in both admin_application/core/MY_Controller.php and application/core/MY_Controller.php. What I'd do is this:

require_once(ROOTPATH.'common/core/Base_Controller.php');
class MY_Controller extends Base_Controller {
}
Contributor

chrisberthe commented Apr 20, 2012

I think you're making a mistake here. FCPATH is in fact the same as ROOTPATH.

Contributor

davidbehler commented Apr 20, 2012

If you use the default folder setup where application, system and index.php are in the same folder, then you are correct...FCPATH is the same as ROOTPATH. But as soon as you deploy the above folder structure where index.php is in fact inside the public_html folder, then FCPATH and ROOTPATH differ. FCPATH always points to the folder where the index.php is and ROOTPATH to the folder where the system folder is. And in some case those two folders are the indeed the same.

Contributor

cryode commented Apr 23, 2012

This could easily be added to application/config/constants.php, but I can see how this could be helpful to others. 👍

Contributor

narfbg commented Oct 23, 2012

Sorry, this one is way too specific and far from what 99% of the users would need. Take @cryode's suggestion about adding it to the constants config.

narfbg closed this Oct 23, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment