Keep getting undefined variable error trying to pass variable into view - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Keep getting undefined variable error trying to pass variable into view (/showthread.php?tid=62642) |
Keep getting undefined variable error trying to pass variable into view - alexandervj - 08-09-2015 Here is my controller Code: $this->form_validation->set_rules('chipNumber', 'Chip Number', 'required'); and here is my view Code: <?php Essentially I'm trying to reload the view if form_validation fails, with the $data array set in the controller. It works ok except everytime I load the view, whether form_validation has had the chance to run or not I get an error that says Undefined Variable $data. Not sure what the right way is to go about this RE: Keep getting undefined variable error trying to pass variable into view - CroNiX - 08-09-2015 $data is only getting defined if the validation fails. Try just putting a $data = array(); before the form validation so it will always exist. RE: Keep getting undefined variable error trying to pass variable into view - Wouter60 - 08-09-2015 The array that you pass to a view (from within your controller), is automatically extracted. If you assigned $data['message'] = ... then your view will recognize $message, not $data. |