Php codeigniter:如何包含包含所有css/js目录的文件
也许这很容易,但我真的被困在里面了。我对codeigniter的了解才几天。Php codeigniter:如何包含包含所有css/js目录的文件,php,codeigniter,Php,Codeigniter,也许这很容易,但我真的被困在里面了。我对codeigniter的了解才几天。这是我的文件目录: webroot |--- assets |-- css |-- js 我想将所有css和js放在一个文件中,然后我只需要将这个文件包含在我的头文件中。 我在stackoverflow和其他教程中读了很多帖子,但我仍然无法成功。 在application\config\constants.php内部 define('ASSET_PATH','asset
这是我的文件目录:
webroot
|--- assets
|-- css
|-- js
我想将所有css和js放在一个文件中,然后我只需要将这个文件包含在我的头文件中。我在stackoverflow和其他教程中读了很多帖子,但我仍然无法成功。
在application\config\constants.php内部
define('ASSET_PATH','assets/');
内部应用程序\config\config.php
$config['header_css']=array('style.css','bootstrap.css');
那么如何在我的页面中加载header_css呢?我的views\login.php中有这段代码<?php
put_headers;
?>
我有一个application\helpers\header\u helper.php
if(!function_exists('add_css')){
function add_css($file='')
{
$str = '';
$ci = &get_instance();
$header_css = $ci->config->item('header_css');
if(empty($file)){
return;
}
if(is_array($file)){
if(!is_array($file) && count($file) <= 0){
return;
}
foreach($file AS $item){
$header_css[] = $item;
}
$ci->config->set_item('header_css',$header_css);
}else{
$str = $file;
$header_css[] = $str;
$ci->config->set_item('header_css',$header_css);
}
}
}
if(!function_exists('put_headers')){
function put_headers()
{
$str = '';
$ci = &get_instance();
$header_css = $ci->config->item('header_css');
// $header_js = $ci->config->item('header_js');
foreach($header_css AS $item){
$str .= '<link rel="stylesheet" href="'.base_url().ASSET_PATH.'/css/'.$item.'" type="text/css" />'."\n";
}
return $str;
}
}
如果(!function_存在('add_css')){
函数add_css($file='')
{
$str='';
$ci=&get_instance();
$header\u css=$ci->config->item('header\u css');
if(空($file)){
返回;
}
if(is_数组($file)){
如果(!is_array($file)&&count($file)config->set_item($header_css',$header_css);
}否则{
$str=$file;
$header_css[]=$str;
$ci->config->set_项($header_css',$header_css);
}
}
}
如果(!function_存在('put_headers')){
函数put_headers()
{
$str='';
$ci=&get_instance();
$header\u css=$ci->config->item('header\u css');
//$header_js=$ci->config->item('header_js');
foreach($header\u css作为$item){
$str.=''“\n”;
}
返回$str;
}
}
类似于hmm..define('ASSET_-PATH',FCPATH.'assets/');
类似于hmm..define('ASSET_-PATH',FCPATH.'assets/'),意思是定义常量什么都不是?define('ASSET_-PATH',FCPATH.'assets/');