Trying to fill options in dropdown by fetching data from database into a view. However I get the error:
Message: Undefined property: CI_Loader::$AdminDataHelper
Filename: forms/user.php
Fatal error: Call to a member function get_colleges() on a non-object in /ci/app/views/includes/forms/user.php on line 54
<select id="college" name="college-selector" >
<?php
foreach ($this->AdminDataHelper->get_colleges() as $colleges)
{
echo "<option value='".$colleges['id']."'>".$colleges['description']."</option>";
}
?>
</select>
My Library class:-
class AdminDataHelper {
public function __construct()
{
$this->CI =& get_instance();
$this->CI->load->model('admin_m');
}
public function get_colleges(){
return $this->CI->admin_m->get_colleges();
}
My model:-
class Admin_M extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
$this->global_db = $this->load->database('global', TRUE);
}
public function get_colleges()
{
$this->global_db->select('id, description');
$this->global_db->from('College');
$result = $this->global_db->get();
$data=$result->result_array();
return $data;
}
In my autoload.php file I added the library.
$autoload['libraries'] = array('database', 'form_validation', 'AdminDataHelper');
Admindatahelper.phpand then$this->admindatahelper->. Follow the examples and see the "naming conventions" section here: codeigniter.com/user_guide/general/…