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 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流