dsadsadsa1231 2016-02-02 13:09
浏览 40

Codeigniter页眉和页脚包括

I'm trying to move from AngularJS to PHP Model-View-Controler framework and something doesn't stick to me, because I do to much repeating. In angular you can do simple include of footer and header and all magic happens in view depending od the route. But in Codeiginiter for every view you need to include header and footer. Is there any good practice in which you don't have to do the much repeating

In angularjs i have simple.

    <div ng-include='"templates/header.html"'></div>
    <div ng-view></div>
    <div ng-include='"templates/footer.html"'></div>

And this is routing

 .when("/", {
        templateUrl: "partials/home.html",
        controller: "PageCtrl"   
    })
    // Pages
    .when("/home", {
        templateUrl: "partials/home.html",
        controller: "PageCtrl",
    })
    .when("/about", {
        templateUrl: "partials/about.html",
         controller: "PageCtrl"
    })

And this is how is done in CodeIgniter

     public function home(){ 
    $this->load->view('templates/header');
    $this->load->view('about');
    $this->load->view('templates/footer');
    }
   public function about(){ 
    $this->load->view('templates/header');
    $this->load->view('index');
    $this->load->view('templates/footer');
    }
  • 写回答

2条回答 默认 最新

  • douqiandai4327 2016-02-02 17:18
    关注

    You can put at the top and on the bottom of files:

    View file:

    <?php
    $this->load->view('templates/header');
    // your main file (index;about etc)
    $this->load->view('templates/footer')
    

    so, in controller you could load just main file i.e.

    Controller file:

    public function home()
    {
        // $this->load->vars($data)
        $this->load->view('index');
    }
    

    Also study Loader class to know how to set variables for all of those files.

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号