在codeigniter子文件夹中添加头部内容

时间:2015-04-04 06:41:51

标签: codeigniter

我在admin_panel

等控制器中使用子文件夹 admin_panel / main.php中的

我使用此代码

public function index()
    {
        $h_data['title'] = 'admin';
        $c_data = array();
        $this->parser->parse('admin/head',$h_data);
        $this->parser->parse('admin/index',$c_data);
    }

和view / admin中的head.php包含:

<html>

<head>



<meta http-equiv="X-UA-Compatible" content="IE=9" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="stylesheet" href="../assets/css/font.css" type="text/css" />
<link rel="stylesheet" href="../assets/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="../assets/css/bootstrap-responsive.css" rel="stylesheet">
<link rel="stylesheet" href="../assets/css/bootstrap-theme.min.css" type="text/css" />

 <!-- HTML5 shim for IE backwards compatibility -->
 <!--[if lt IE 9]>
 <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
 <![endif]-->
<link rel="stylesheet" type="text/css" href="../assets/css/admin_style.css" />

<script type="text/javascript" src="../assets/js/jquery.min.js"></script>
<script type="text/javascript" src="../assets/js/bootstrap.min.js"></script>

<title> {title} </title>

</head>

在根项目中存在asstes文件夹,但是当刷新页面时,所有头标记返回404并且未找到???

2 个答案:

答案 0 :(得分:0)

你可以尝试

public function index() {
// Load Parser library or autoload it.
$this->load->library('parser');

$data['title'] = "Page Title";
$data['base_url'] = base_url(); // Make sure you add url helper to autoload.

// May need to add true, i.e $this->parser->parse('header', $data, true);
$data['header'] = $this->parser->parse('header', $data); 

// May need to add true, i.e $this->parser->parse('footer', NULL, true); Null No Data
$data['footer'] = $this->parser->parse('footer');

$this->parser->parse('content', $data);

}

在内容视图区域

<?php echo $header;?>

Content

<?php echo $footer;?>

标题视图示例

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
<title><?php echo $title;?></title>
<base href="<?php echo base_url();?>"></base>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>assets/admin/css/bootstrap.css" media="screen">
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>assets/admin/css/custom.css" media="screen">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>assets/admin/js/common.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>assets/admin/js/filemanager.js"></script>
</head>
<body>

页脚视图示例

<footer id="footer">
<br />
</footer>
</div>

<script type="text/javascript" src="<?php echo base_url();?>assets/admin/js/bootstrap.min.js"></script>
</body>
</html>

自动加载网址助手

$autoload['helper'] = array(
    'url',
    'file',
    'form',
    'text',
    'html',
    'date'
 );

答案 1 :(得分:0)

我找到答案.htaccess不适合代码发生此错误。我使用这个htaccess并正常工作:)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]