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 python安卓开发
  • ¥15 使用R语言GD包一直不出结果
  • ¥15 计算机微处理器与接口技术相关问题,求解答图片的这个问题,有多少个端口,端口地址和解答问题的方法和思路,不要AI作答
  • ¥15 如何根据一个截图编写对应的HTML代码
  • ¥15 stm32标准库的PID角度环
  • ¥15 ADS已经下载好了,但是DAS下载不了,一直显示这两种情况,有什么办法吗,非常急!
  • ¥100 Excel 点击发送自动跳转outlook邮件
  • ¥15 gis中用栅格计算器或加权总和后图层不显示,值也明显不对
  • ¥15 python使用python-pptx如何给幻灯片添加只读密码。
  • ¥15 深度神经网络传递自变量损失