根据Codeigniter中的另一个下拉列表填充下拉列表

时间:2013-10-11 10:37:35

标签: ajax codeigniter oop drop-down-menu

我正在尝试根据另一个下拉菜单选项填充下拉菜单。我在互联网上搜索了解决方案,并发现使用AJAX的最佳方法是使用AJAX,我以前从未使用过AJAX,也无法使其正常工作。希望你们能帮助我。

查看:

<?php
echo form_dropdown('grades', $grades);

//This is the dropdownmenu that's based on the grades selection
echo form_dropdown('classes', $classes);
?>

MODEL:

function get_all_grades()
{
    $query = $this->db->get('grades');
    $result = $query->result();

    foreach($result as $row)
    {
        $options[$row->id] = $row->grades;
    }

    return $options;
}

function get_all_classes($grade = null)
{
    $query = $this->db->get('classes');
    $result = $query->result();

    foreach($result as $row)
    {
        $options[$row->id] = $row->name;
    }

    return $options;
}

控制器:

function registerform()
{
    $this->load->model('school_info_model');

    if ($query = $this->school_info_model->get_all_grades())
    {
        $data['grades'] = $query;
    }

    if ($query = $this->school_info_model->get_all_classes())
    {
        $data['classes'] = $query;
    } 

    $data['main_content'] = 'register_form_view';
    $this->load->view('template/template.php', $data);
}

0 个答案:

没有答案