I have 2 functions/methods in the same controller in CodeIgniter like this:
public function _get_page_settings() {
$page_settings = $this->page_model->get_page_settings();
$data['ps'] = $page_settings;
}
public function registration() {
$this->_get_page_settings();
$this->load->view('page_registration', $data);
}
The first method _get_page_settings() grabs some stuff from db and store it in a variable ps inside data array.
I want to use this method in many other methods inside this controller.
So, how to send data correctly to registration() because this code above is not working OK. It throw this error in my view: Message: Undefined variable: data on line 70 which is this line: $this->load->view('page_registration', $data);
EDIT: SOLVED!
I have finally figured it out. You can do it like this:
public function _get_page_settings() {
$data['ps'] = $this->page_model->get_page_settings();
$this->ps = $data['ps'];
}
public function registration() {
$this->_get_page_settings();
$this->load->view('page_registration', $this->ps);
}
And to output it in the view e.g.:
<?php echo $this->ps->page_name; ?>