Php 如何访问CodeIgniter中的静态资产?
我正在为一个项目使用CodeIgniter 文件夹结构-htdocs/NewProject/application 我创建了一个名为Home-applications/controllers/Home.php的控制器 我创建了一个视图-applications/view/index.php 我可以毫无问题地访问index.php 我的路线是Php 如何访问CodeIgniter中的静态资产?,php,codeigniter,static,routes,Php,Codeigniter,Static,Routes,我正在为一个项目使用CodeIgniter 文件夹结构-htdocs/NewProject/application 我创建了一个名为Home-applications/controllers/Home.php的控制器 我创建了一个视图-applications/view/index.php 我可以毫无问题地访问index.php 我的路线是 $route['default_controller'] = "home"; 我可以访问localhost:8888/NewProject-这将带我回到主
$route['default_controller'] = "home";
我可以访问localhost:8888/NewProject-这将带我回到主页#索引
我把一些css和图像文件夹放在视图文件夹中。
如何访问图像和css
尝试访问NewProject/css/xxx.css会导致找不到错误
是否有其他文件夹可以添加这些静态文件?是否需要向routes文件中添加任何内容?将结构设置为如下所示
root (is your root directory)
/application
/system
/static
/images
/css
/js
在config.php
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
// use this if your project is in root
$config['base_url'] = 'http://example.com/';
// use this if your project is in folder/subfolders
//$config['base_url'] = 'http://example.com/newproject/liveproject/';
/*
| -------------------------------------------------------------------
| Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['helper'] = array('url', 'file');
*/
$autoload['helper'] = array('url');
在Autoload.php
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
// use this if your project is in root
$config['base_url'] = 'http://example.com/';
// use this if your project is in folder/subfolders
//$config['base_url'] = 'http://example.com/newproject/liveproject/';
/*
| -------------------------------------------------------------------
| Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['helper'] = array('url', 'file');
*/
$autoload['helper'] = array('url');
在您的视图文件中
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>static/style.css" />
<img src="<?php echo base_url(); ?>static/images/myimage.jpg" alt="" />
当我将$config['base\u url']
保留为解决方案的空字符串Thx时,这对我有效