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

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Faster Way to Load Models and Helpers (/showthread.php?tid=26264)



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(){
    }
}