Created
September 25, 2012 13:22
-
-
Save mpmont/3781778 to your computer and use it in GitHub Desktop.
Loading blade views automatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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