doutao4480 2013-01-04 17:12
浏览 147
已采纳

Codeigniter相对路径文件

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.

  • 写回答

1条回答 默认 最新

  • dongsu4345 2013-01-04 17:15
    关注

    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");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line