Layout.php 没有显示 header.php 部分
Layout.php is not showing the header.php part
我有 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 文件。 So.There 是 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 部分。
我认为问题出在短标签上,
<?php include 'header.php';?>
但我想说,在 codeigniter 使用中,
$this->load->view("header.php");
使用这个
$path = APPPATH.'views/header.php';
<?php include $path; ?>
Codeigniter can call path with APPPATH
. Its CI predefined varaiable
将此行更改为
<?php include 'header.php';?>
检查您的 php 配置是否 short_open_tag = On 以及您的文件位置路径。
你也可以试试这个:
但是对于 codeigniter,最好这样使用:$this->load->view('header.php');
我发现加载页眉和页脚的最佳方法是创建一个 views/template_view.php,您可以在其中加载页眉和页脚,这样就不必每次都加载它。
views/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);
}
我有 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 文件。 So.There 是 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 部分。
我认为问题出在短标签上,
<?php include 'header.php';?>
但我想说,在 codeigniter 使用中,
$this->load->view("header.php");
使用这个
$path = APPPATH.'views/header.php';
<?php include $path; ?>
Codeigniter can call path with
APPPATH
. Its CI predefined varaiable
将此行更改为
<?php include 'header.php';?>
检查您的 php 配置是否 short_open_tag = On 以及您的文件位置路径。
你也可以试试这个:
但是对于 codeigniter,最好这样使用:$this->load->view('header.php');
我发现加载页眉和页脚的最佳方法是创建一个 views/template_view.php,您可以在其中加载页眉和页脚,这样就不必每次都加载它。
views/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);
}