In creating dropdown in my project encounters problems(errors). I'm very new to codeigniter.
Please check and advise what is wrong with with my code?
Model
Public function get_region()
{
$return = array();
$query = $this->db->get('region')->result_array();
if( is_array( $query ) && count( $query ) > 0 )
{
$return[''] = 'please select';
foreach($query as $row)
{
$return[$row['id']] = $row['r_e_name'];
}
}
return $return;
}
Controller
public function index()
{
$this->load->model('country_model');
$data['countries'] = $this->country_model->get(false);
$data['page_title'] = "Countries";
$data['return']=$this->country_model->get_region();
$this->template->show('countries', $data);
}
View
<tr>
<td>
<?php echo form_label('Region Name *', 'r_e_name'); ?>
</td>
<td>
<?php echo form_dropdown('r_e_name', $return);?>
</td>
</tr>
Errors
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: return
Filename: views/countries_add.php
Line Number: 17
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: helpers/form_helper.php
Line Number: 331