Layout.php没有显示header.php部分

时间:2015-10-28 10:11:16

标签: php codeigniter codeigniter-2 codeigniter-3

我有Html,如下所示。

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <!-- Meta, title, CSS, favicons, etc. -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
    </head>
    <body style="background:#F7F7F7;">
        <div class="">
        </div>
    </body>
</html>

我将这个html分成了两个PHP文件。那么。Header.php。如下所示。

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>

layout.php中

<!DOCTYPE html>
<html lang="en">

    <? include 'header.php';?>

    <body style="background:#F7F7F7;">
        <div class="">
        </div>
    </body>
</html>

问题

Layout.php没有显示header.php部分。

5 个答案:

答案 0 :(得分:1)

我认为问题出在短标签上,

<?php include 'header.php';?>

但我会说,在codeigniter使用中,

$this->load->view("header.php");

答案 1 :(得分:1)

将此行更改为

<?php include 'header.php';?>

答案 2 :(得分:1)

我发现最好的方法是加载页眉和页脚是创建一个views / template_view.php,你可以在其中加载页眉和页脚,这样你就不必每次都加载它。

<强>视图/ template_view.php

<?php $this->load->view('header');?>

<?php $this->load->view($page);?>

<?php $this->load->view('footer');?>

在控制器上然后您需要做的就是

public function index() {
   // Would be the name of the view you would like for this function / controller
   $data['page'] = 'somefile_view'; 
   $this->load->view('template_view', $data);
}

答案 3 :(得分:0)

使用此

$path = APPPATH.'views/header.php';
<?php include $path; ?>
  

Codeigniter可以使用APPPATH调用路径。其CI预定义可变

答案 4 :(得分:0)

检查你的php配置是否有short_open_tag = On以及你的文件位置路径。

你也可以尝试这个:

但对于codeigniter,最好这样使用:$ this-&gt; load-&gt; view(&#39; header.php&#39;);