Codeigniter下拉列表引发错误,并且没有显示任何数据


Codeigniter dropdown throws error and no data is displaying

在下面的代码点火器代码中,我放置了控制器、模型和视图。在其中我已经实现了大学名称下拉,但它抛出错误

未定义的变量:select_options,为提供的参数无效foreach()

下拉列表中没有数据。请帮我解决这个问题。

控制器

function add_content() {
    $data = array();
    $this->is_logged_in();
    $this->load->model('membership_model');
    $data['select_options'] = $this->membership_model-> validate();
    $this->load->view('login_form', $data);
}
function validate_credentials() {       
    $this->load->model('membership_model');
    $query = $this->membership_model->validate();
    if($query) { // if the user's credentials validated...
        $data = array(
            'username' => $this->input->post('username'),
            'is_logged_in' => true
        );
        if($query->num_rows()>0) {
            $status = $query->row()->account_status;
        } else {
            $status = ''; 
        }
        //Account active
        if($status == 'active') {
            $this->session->set_userdata($data);
            redirect('site1/members_area');
        } else if ($status == 'inactive') { //Account In active
            $this->inactive();
        } else { // incorrect username or password
            $this->invalid();
        }
    }   
}   

型号

function validate() {
    $this->db->where('username', $this->input->post('username'));
    $this->db->where('password', md5($this->input->post('password')));
    $this->db->select('college_name'); 
    $this->db->from('membership');
    $this->db->where('college_name');
    $query = $this->db->get('membership');
    foreach($query->result_array() as $row) {
        $data[$row['college_name']];
    }
    return $query;
}

查看

<?php 
    echo form_open('login/validate_credentials');
    echo form_input('username', 'Username');
    echo form_password('password', 'Password');
    echo form_dropdown('college_name', $select_options);
    echo form_submit('submit', 'Login');
    echo anchor('login/signup', 'Create Account');
    echo form_close();
?>

尝试类似的东西

function validate()
{
    $this->db->where('username', $this->input->post('username'));
    $this->db->where('password', md5($this->input->post('password')));
    $this->db->select('college_name'); 
    $this->db->from('membership');
    $this->db->where('college_name');
    $query = $this->db->get('membership');
    $data = [];
    foreach($query->result_array() as $row){
      $data[$row['college_name']] = $row['college_name'];
    }
    return $data;
}

阵列应该像这个

$options = array(
              'small'  => 'Small Shirt',
              'med'    => 'Medium Shirt',
              'large'   => 'Large Shirt',
              'xlarge' => 'Extra Large Shirt',
            );
echo form_dropdown('shirts', $options, 'large');
// Would produce:
<select name="shirts">
<option value="small">Small Shirt</option>
<option value="med">Medium Shirt</option>
<option value="large" selected="selected">Large Shirt</option>
<option value="xlarge">Extra Large Shirt</option>
</select>