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 手机淘宝抓清除消息接口
  • ¥15 C#无selenium
  • ¥15 LD衰减计算的结果过大
  • ¥15 用机器学习方法帮助保险公司预测哪些是欺诈行为
  • ¥15 计算300m以内的LD衰减
  • ¥15 数据爬取,python
  • ¥15 怎么看 cst中一个面的功率分布图,请说明详细步骤。类似下图
  • ¥15 为什么我的pycharm无法用pyqt6的QtWebEngine
  • ¥15 FOR循环语句显示查询超过300S错误怎么办