【问题标题】:How to include header file in main file in the View Folder using php Codeigniter?如何使用 php Codeigniter 在视图文件夹的主文件中包含头文件?
【发布时间】:2015-12-25 13:50:49
【问题描述】:

我在查看文件夹中有两个文件夹

  1. 布局文件夹:- 在这个文件夹中我创建了两个文件 header.php 和 footer.php

  2. 代理文件夹:- 在此文件夹中 iIhave 主文件dashboard.php。

我想将布局文件夹中的页眉和页脚文件包含到 Dashboard.php。

我正在使用此代码:

<?php include('../layout/header.php') ?>

【问题讨论】:

    标签: php codeigniter directory-structure


    【解决方案1】:

    试试这个:

    $this->load->view('layout/header');
    $this->load->view('layout/footer');
    

    在控制器功能中只需使用以下代码加载:

    public function index()
        {
                $this->load->view('layout/header');
                $this->load->view('agent/dashboard');
                $this->load->view('layout/footer');
        }
    

    【讨论】:

    • 但我想在dashboard.php中包含这些文件
    • 您的意思是在视图文件中,对吗?试试这个就行了。
    • 谢谢,它的工作。但是我有dout,如果我按这个顺序加载它是如何工作的 $this->load->view('layout/header'); $this->load->view('布局/页脚'); $this->load->view('admin/dashboard.php');它如何自动识别在仪表板中添加页眉、页脚的位置?
    • 正确阅读 codeigniter 文档。 codeigniter.com/user_guide/general/views.html
    【解决方案2】:

    文件夹结构

    应用程序/视图/模板
    应用程序/视图/站点

    $this->load->view('template/header');
    $this->load->view('site/dashboard');
    $this->load->view('template/footer');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-24
      • 1970-01-01
      • 2010-12-05
      • 2023-03-12
      • 1970-01-01
      • 2017-11-09
      • 2011-06-30
      相关资源
      最近更新 更多