【发布时间】:2014-01-03 20:51:07
【问题描述】:
我在 codeigniter 中包含文件夹/文件时遇到问题,这就是我认为文件的结构方式。
-application
-model
-controller
-view
-auth
-login.php //I want to include header.php, sidebar and footer on this file
-includes
-header.php
-sidebar.php
-footer.php
在 application/view/auth/login.php 我有 include('../../include/header'); 但不起作用,我尝试了其他几种方法,也没有工作,我也不能使用绝对路径,因为文件位于应用程序文件夹中。
编辑:
我的视图文件夹中的示例我有 index.php 文件,并且我有以下代码
<?php
include('includes/header.php');
include('includes/sidebar.php');
?>
<div id='content'>
<h3>Title</h3>
<p>contents contents</p>
</div>
<?php include('/includes/footer.php'); ?>
现在视图文件夹中有另一个名为 auth 的文件夹,我在其中有一个名为 login.php 的文件,并包含以下代码
<?php include(../includes/header.php);?> //this doesn't work
<?php include(../includes/sidebar.php);?> //this doesn't work
<div id='form'>
<form>
</form>
</div>
<?php include(../includes/header);?> //this doesn't work
在我的控制器上我有
<?php
class Index extents CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('index'); //this works and loads all the includes
}
}
另一个控制器不工作的例子
<?php
class Login extents CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('auth/login'); //this works but doesn't load the includes
//in the login.php file found inside the auth
//folder
}
}
【问题讨论】:
-
@Ali 你应该阅读 OP 的问题,该链接对他没有帮助
标签: php file codeigniter path directory