Skip to content

Update MY_Controller.php #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions core/MY_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class MY_Controller extends CI_Controller
* view, layout and any asides
*/
protected $data = array();

/**
* ! For those who don't like array syntax !
* An object of variables to be passed through to the
* view, layout and any asides
*/
protected $odata;

/**
* The name of the layout to wrap around the view.
Expand Down Expand Up @@ -64,7 +71,7 @@ class MY_Controller extends CI_Controller
public function __construct()
{
parent::__construct();

$this->odata = new stdClass;
$this->_load_models();
$this->_load_helpers();
}
Expand Down Expand Up @@ -111,6 +118,9 @@ protected function _load_view()
// If $this->view isn't empty, load it. If it isn't, try and guess based on the controller and action name
$view = (!empty($this->view)) ? $this->view : $this->router->directory . $this->router->class . '/' . $this->router->method;

// Merging $data with $odata
$this->data = array_merge($this->data, get_object_vars($this->odata));

// Load the view into $yield
$data['yield'] = $this->load->view($view, $this->data, TRUE);

Expand Down Expand Up @@ -198,4 +208,4 @@ private function _load_helpers()
$this->load->helper($helper);
}
}
}
}