Hello,
What is the easiest way to get CI application path, without need to set it manually in the configuration or code?
BASEPATH variable will return system pat.
Thanks for help
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
May 23, 2011 5:21am
Subscribe [5]#1 / May 23, 2011 5:21am
Hello,
What is the easiest way to get CI application path, without need to set it manually in the configuration or code?
BASEPATH variable will return system pat.
Thanks for help
#2 / May 23, 2011 6:57am
use getcwd() function.
#3 / May 23, 2011 7:22am
Constants
APPPATH = application directory path
SYSDIR = system directory path
Look at index.php
InsiteFX
#4 / Aug 31, 2011 1:07am
Even though I’ve upgraded to the latest CodeIgniter the index.php continues to resolve the application path (APPPATH) as being inside the system directory. It appears to simply append $application_folder to BASEPATH. The latest version of CodeIgniter, I believe, moves the application directory outside of the system directory.
On GitHub it appears that the index.php file has not changed. Am I missing something or should this be fixed? If it should I will create an issue on Github. If not, I’d like to know what I’m missing. Thanks in advance.
#5 / Aug 31, 2011 2:50am
You also need to update your index.php file with the new one
#6 / Aug 31, 2011 5:03pm
SYSDIR is only the name of the system folder (i.e. ‘system’). BASEPATH is the full path to the system folder.
index.php first checks $application_folder to see if it is a directory and then checks BASEPATH/$application_folder. If you moved your application folder somewhere else then you need to supply a full server path.
// The path to the "application" folder
if (is_dir($application_folder))
{
define('APPPATH', $application_folder.'/');
}
else
{
if ( ! is_dir(BASEPATH.$application_folder.'/'))
{
exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF);
}
define('APPPATH', BASEPATH.$application_folder.'/');
}
#7 / Aug 31, 2011 5:59pm
index.php first checks $application_folder to see if it is a directory and then checks BASEPATH/$application_folder. If you moved your application folder somewhere else then you need to supply a full server path.
A somewhat recent update to CodeIgniter moved the application folder outside of the system folder. So BASEPATH.’/’.$application_folder is no longer the correct location for this directory. Correct?
Sorry if I’m missing something but my BASEPATH includes /system/ in it.
#8 / Aug 31, 2011 6:29pm
A somewhat recent update to CodeIgniter moved the application folder outside of the system folder. So BASEPATH.ā/ā.$application_folder is no longer the correct location for this directory. Correct?
They moved the default application folder path to outside the system folder in CI 2.0 but it’s fine to leave it inside the system folder. It will work fine either way.
Sorry if Iām missing something but my BASEPATH includes /system/ in it.
Sorry if I confused you. BASEPATH is the full server path to your system folder. (i.e. “/var/www/mysite.com/codeigniter/system/”) so it is supposed to include the system folder.
SYSDIR is just the name of the system folder without the rest of the path (i.e. “system”). I’m not sure why it’s in there because it’s not used anywhere in the core. I think maybe it’s something added for ExpressionEngine but I’m not sure.
#9 / Aug 31, 2011 11:15pm
So shouldn’t APPPATH = ‘/full/path/to/application/’ and BASEPATH be ‘/full/path/to/system/’? My my case APPPATH is ‘/wrong/path/to/system/application/’.
I’ll just have to figure out why by going line by line (which I’ve done twice and can’t seem to find it).
Here is my entire index.php from my app.
#10 / Aug 31, 2011 11:54pm
and your files look like this?
public_html/
—application/
—system/
—index.php
if you moved application and system then you need to use full paths.
#11 / Sep 01, 2011 12:48am
and your files look like this?
public_html/
—application/
—system/
—index.phpif you moved application and system then you need to use full paths.
That is exactly right. The problem is, I’d like to keep this dynamic for my three environments: dev, staging, live.
#12 / Sep 01, 2011 2:54am
ah ok. you can do something like this https://raw.github.com/gist/b0fb248833620a05f7f4/5fc1cb7703ed94aaa67fa5bc7a9029c12ab884c2/CIindex.php
#13 / Sep 02, 2011 11:34am
ah ok. you can do something like this https://raw.github.com/gist/b0fb248833620a05f7f4/5fc1cb7703ed94aaa67fa5bc7a9029c12ab884c2/CIindex.php
Thanks! I did something very similar to this.