简体   繁体   English

Codeigniter相对路径文件

[英]Codeigniter relative path file

I am new to codeigniter (and php in general) and I am following the tutorial to learn it. 我是codeigniter(和一般的php)的新手,我正在按照教程学习它。 Following this link : https://www.codeigniter.com/user_guide/tutorial/static_pages.html 点击此链接: 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 ? 我的问题是:这个脚本是从application / controllers / pages.php运行的,所以不是相对于当前脚本给file_exists的路径? that is it should point to application/controllers/application/views/pages/'.$page.'.php'. 它应该指向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 ? 这个php问题还是codeigniter?

Thanks. 谢谢。

All paths are relative to the entry script (likely index.php or whatever Codeigniter uses). 所有路径都相对于入口脚本(可能是index.php或Codeigniter使用的任何路径)。

To get paths relative to the current script use the __FILE__ constant. 要获取相对于当前脚本的路径,请使用__FILE__常量。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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