Layout.php is not showing the header.php part

孤街醉人 提交于 2020-01-07 09:04:06

问题


I have Html like below.

<!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>

I divided this html in two PHP files. So.There is Header.php. Like Below.

<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>

Problem

Layout.php is not showing the header.php part.


回答1:


I think the problem is with short tags,

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

But i would say, in codeigniter use,

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



回答2:


change this line as

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



回答3:


I find the most better way is for loading header and footer is create a views/template_view.php where you load your header and footer that way you do not have to load it every time.

views/template_view.php

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

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

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

On controller then all you would have to do is

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);
}



回答4:


use this

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

Codeigniter can call path with APPPATH. Its CI predefined varaiable




回答5:


check your php configuration for short_open_tag = On and also for your file location path.

you can try this one also :

But for codeigniter it is better to use like this : $this->load->view('header.php');



来源:https://stackoverflow.com/questions/33388208/layout-php-is-not-showing-the-header-php-part

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