I’m using files and streams in codeigniter, and one problem I ran into was that functions like fopen were not able to detect a file in the same folder. For example,
If both my function and file is in the HELPER folder, I can’t simply specify fopen(‘file’,’r’) because it just won’t detect it.
So I went on the site to look at the documentation regarding files, and this is what it specifies:
Note: The path is relative to your main site index.php file, NOT your controller or view files. CodeIgniter uses a front controller so paths are always relative to the main site index.
So I changed the path to application/helper/filename and it worked.
I know this is caused by some type of rerouting due to the front controller(index.php), but my understanding is incomplete. Could someone explain to me what exactly happens in CI when I try something like fopen?
Thank you for your time.
That is pretty simple. There is one and only one file that handles controllers/models/helpers (which is called a “Front Controller”):
/index.php. So everything happens through this script.When you need to include something, paths are relative to
index.php. A good practice would be to include your files using CodeIgniter environment constants. You can take a look at this: http://jimdoescode.blogspot.com/2011/01/some-codeigniter-constants.html.For instance: