duanqinbi9029 2016-09-16 02:08
浏览 31
已采纳

Codeigniter处理控制器调用视图的最佳方法

i just want to know if this is a good way in adding fragmented views.

lets say "header.php" is like this

    <!DOCTYPE html>
<html>
  <head>
    <title>Bootstrap Admin Theme v3</title>
    some links..
  </head>
</html>

then "body.php" is like this

<!DOCTYPE html>
<html>
  <body>
    lots of stuff..
  </body>
</html>

lastly "scripts.php"

<!DOCTYPE html>
<html>
  <body>
    some scripts..
  </body>
</html>

then in my "MyController.php"

$this->load->view('header');
$this->load->view('body');
$this->load->view('scripts');
  • 写回答

3条回答 默认 最新

  • dongsou0083 2016-09-16 03:24
    关注

    The best way I find is create a default view.

    views > default_view.php
    
    views > includes > header_view.php
    
    views > includes > footer_view.php
    
    views > information > contact_view.php
    

    On that view

    <?php
    
    $this->load->view('includes/header_view');
    
    $this->load->view($content_page);
    
    $this->load->view('includes/footer_view');
    
    ?>
    

    Then on the controller to load view this way you do not have to load the header and footer views all the time.

    Following the Codeigniter StyleGuide

    Filename: Example.php

    <?php
    
    class Example extends CI_Controller {
    
    public function index() {
    
       // Add any other variables
    
       $data['content_page'] = 'information/contact_view'; // This will be your content page example 
    
       $this->load->view('default_view', $data);
    
    }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?