I use the following code in my controller. But the data[‘msg’] is not being passed to the view file.
Code:
class Operator{
public function view ($page)
{
if ( ! file_exists('application/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = $this->getTitle($page);
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
public function create_company()
{
// some code
$data['msg1']='my mesg';
redirect('operator/view/operator_success','refresh');
}
};
When operator_success(view page) is loaded it show error message: variable ‘$msg1’ not defined.
After Redirect you cannot use the variable or array. Instead setting the variable keep in session or CodeIgniter Flash Data.
After redirect you can simply call the flashdata.
You must initialize the session before use, either autoload the session library or load manually.
[ 1 ] Autoload the session library (config/autoload.php)
[ 2 ] Manually load the library
see more about session and flash data here. Hope this helps you. Thanks!!