CodeIgniter Forums
Faster Way to Load Models and Helpers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Faster Way to Load Models and Helpers (/thread-26264.html)



Faster Way to Load Models and Helpers - El Forum - 01-09-2010

[eluser]ShoeLace1291[/eluser]
I have controllers that use the same models, helpers, and libraries in every function in that controller. Is there a way to load models, etc one time in the beginning of a controller instead of loading it in every single function in that controller? I don't want to autoload it(I already know it so don't explain it). Something like

<?php

class Page extends Controller {

$this->load->model('pagemodel');

function index(){

$this->pagemodel->page();

}

function another(){

$this->pagemodel->page();

}
}


Faster Way to Load Models and Helpers - El Forum - 01-09-2010

[eluser]WebsiteDuck[/eluser]
Code:
class Page extends Controller {

    function __construct(){  

        parent::Controller();    

        $this->load->model('pagemodel');

    }

    function index(){

      $this->pagemodel->page();
    
    }

    function another(){

      $this->pagemodel->page();

    }
}



Faster Way to Load Models and Helpers - El Forum - 01-10-2010

[eluser]Sbioko[/eluser]
Code:
class Page extends Controller {

    function Page() {
        $this->load->model(‘pagemodel’);
        $this->pagemodel->page();
    }

    function index(){
    }

    function another(){
    }
}