Welcome Guest, Not a member yet? Register   Sign In
CI Relative Paths
#1

[eluser]stevea[/eluser]
I have the directory structure shown in the attached figure. The
editor.php controller has the line:

Code:
$this->config->load('uploader_settings', TRUE);

But uploader_settings.php is just:

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require('../config.php');



/* End of file uploader_settings.php */
/* Location: ./system/application/config/uploader_settings.php */

My question is, how does require('../config.php') load the config file? Is CI making some assumptions about relative paths?

If the line in editor.php
Code:
$this->config->load('uploader_settings', TRUE);
is actually including uploader_settings.php in editor.php, then ('../config.php'); would be running from editor.php and ../ would take us to the application directory, but there's no config.php there.

If the config-> load line doesn't actually include uploader_settings.php into editor.php, so require('../config.php') is running from config/uploader_settings.php, then ../ would again take us to the application directory, where there is no config.php file.

Does anyone see how require('../config.php'); loads config.php? Is CI making its own directory assumptions, or forgiving an error in the code and going to the right place?

Thanks
#2

[eluser]stevea[/eluser]
I figured this out. The ../ is being evaluated relative to the ci folder. Then ../ takes you to a config.php that is just for this project, which is what is wanted here. I'm still not sure why the ../ is evaluated with respect to ci, though.
#3

[eluser]InsiteFX[/eluser]
../ moves you up one directory level.
#4

[eluser]stevea[/eluser]
Yes. Of course. But it's not necessarily from the directory the script is in.The script that had the

include(../config.php)

was down several levels from the ci folder but this include got resolved with respect to ci ! That is, it went back up one level to the project directory and then down to the config.php in that directory. I stuck some code into the script to show the include path there:

Code:
$fp = fopen('dbg' . ".txt", 'w');
fwrite($fp,"\n include path="   . get_include_path());
fclose($fb);
  
require('../config.php');

And this got printed:
include path=.:/usr/share/php:/usr/share/pear

Clearly CI isn't using that either. CI seems to set its own paths and use those to resolve relative paths.

It's all very confusing, at this point.
#5

[eluser]Aken[/eluser]
The path is relative to the location of index.php
#6

[eluser]stevea[/eluser]
Yes! Thank you. That certainly works!

But does that mean that "." (current directory) down in

ci/applications/config/uploader_settings.php

is actually ci, the directory holding index.php?

Is what's happening:
1. we're coming into index.php first and then
2. everything gets loaded, effectively, into it, so by the time something runs it's actually part of index.php

Any further explanation, or pointers to where this might be documented, would be a big help.

Thanks,
Steve







Theme © iAndrew 2016 - Forum software by © MyBB