Welcome Guest, Not a member yet? Register   Sign In
Autoloading views
#1

[eluser]dailygrind[/eluser]
How do I autoload views in a RoR way? Is it possibile? (I'm trying get rid of the code for loading views on each method). Is there a CI's best practice for this?

thanx for helping.
#2

[eluser]pickupman[/eluser]
You could try using [url="http://ellislab.com/codeigniter/user-guide/general/hooks.html"]hooks[/url]. Create a hook on "post_controller". Send params to load view based on uri string. Haven't tried, but looks like this may be possible.
#3

[eluser]Derek Allard[/eluser]
You might also be interested in _output(), depending on your uses, or in building a base controller to handle it for you.
#4

[eluser]dailygrind[/eluser]
Thanks for tips. I tried Derek's way and it worked..

Code:
<?
class APP_Controller extends Controller {        
    public $vars;
    public $no_layout = false;
    
    function __construct() {        
        parent::__construct();    
        $this->vars["contents"] = "";
    }        
    
    function _output() {
        if(!$this->no_layout) {
            $this->vars["contents"] = $this->load->view($this->router->class."/".$this->router->method,$this->vars,true);
  
            $this->load->view("layout/application",$this->vars);
            echo $this->output->get_output();
        }
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB