简体   繁体   中英

Codeigniter relative path file

I am new to codeigniter (and php in general) and I am following the tutorial to learn it. Following this link : https://www.codeigniter.com/user_guide/tutorial/static_pages.html

in the controller it checks whether the a file exists using

 if ( ! file_exists('application/views/pages/'.$page.'.php'))

My question is: this script is running from application/controllers/pages.php so isn't the path given to file_exists relative to the current script ? that is it should point to application/controllers/application/views/pages/'.$page.'.php'.

However this is not the case and the path in fact checks files relative to the path root ! So is this php matter or codeigniter ?

Thanks.

All paths are relative to the entry script (likely index.php or whatever Codeigniter uses).

To get paths relative to the current script use the __FILE__ constant.

file_exists(dirname(__FILE__) . "/path/to/file.php");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM