Codeigniter File Paths

有些话、适合烂在心里 提交于 2019-12-07 08:25:26

问题


sorry to bother but I am having some confusion with filepaths within codeigniter, as you may or may not know CI lays out its file system as follows:

-application:
             -controllers
             -views
             -models
-system(contains CI framework)

I have created a css file and have some images saved in the a resources folder like so:

 -application:
             -controllers
             -views
             -models
-system(contains CI framework)

-resources
     -img001
     -style.css

I was wondering whether someone could point me in the right direction to accessing the resources folder using relative paths.


回答1:


You can use base_url function. To use this function you have to load url helper

You can load wherever it required as below:

$this->load->helper('url');

Or you can set in autoload.php.

echo base_url("resources/img001/img_name.jpg");
echo base_url("resources/style.css");



回答2:


echo FCPATH."resources/img001/img_name.jpg";
echo FCPATH."resources/style.css";

Constant FCPATH will return system's path to Your front controller's file (index.php at root of Your CI-App)



来源:https://stackoverflow.com/questions/21753992/codeigniter-file-paths

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!