Skip to content

Instantly share code, notes, and snippets.

@mpmont
Created September 25, 2012 13:22
Show Gist options
  • Select an option

  • Save mpmont/3781778 to your computer and use it in GitHub Desktop.

Select an option

Save mpmont/3781778 to your computer and use it in GitHub Desktop.
Loading blade views automatically
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
public $data = array();
public $view;
public function __construct() {
parent::__construct();
$this->view = ($this->view !== null) ? $this->view : $this->router->directory . $this->router->class . '/' . $this->router->method;
}
/**
* Remap the CI request, running the method
* and loading the view
*/
public function _remap($method, $arguments) {
if (method_exists($this, $method)) {
call_user_func_array(array($this, $method), array_slice($this->uri->rsegments, 2));
} else {
show_404(strtolower(get_class($this)).'/'.$method);
}
$this->_load_view();
}
public function _load_view() {
if(!empty($this->view) && $this->view != false) {
echo $this->load->blade($this->view, $this->data);
}
}
}
/* End of file MY_Controller.php */
/* Location: ./application/controllers/MY_Controller.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment