Last active
May 8, 2016 08:46
-
-
Save cyberfly/41be716aaed12f464733fb97af2d9c3f to your computer and use it in GitHub Desktop.
CodeIgniter 3 MY_Controller
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 | |
class MY_Controller extends CI_Controller | |
{ | |
protected $data = array(); | |
function __construct() | |
{ | |
parent::__construct(); | |
$this->data['pagetitle'] = 'My First CMS'; | |
} | |
protected function render($the_view = NULL, $template = 'backend') | |
{ | |
if($template == 'json' || $this->input->is_ajax_request()) | |
{ | |
header('Content-Type: application/json'); | |
echo json_encode($this->data); | |
} | |
elseif(is_null($template)) | |
{ | |
$this->load->view($the_view,$this->data); | |
} | |
else | |
{ | |
$this->data['content'] = (is_null($the_view)) ? '' : $this->load->view($the_view,$this->data, TRUE); | |
$this->load->view('templates/'.$template.'/index', $this->data); | |
} | |
} | |
} | |
class Admin_Controller extends MY_Controller | |
{ | |
function __construct() | |
{ | |
parent::__construct(); | |
} | |
} | |
class Public_Controller extends MY_Controller | |
{ | |
function __construct() | |
{ | |
parent::__construct(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment