CI和GroceryCRUD DB更新行

时间:2013-02-12 21:38:31

标签: ajax controller updates grocery-crud

我使用CI 2.1和GroceryCRUD 1.3.3,我在我的控制器管理员中使用这个2功能,但我不能更新行的值我有2个值0/1:  通过点击链接或使用AJAX(首选)

,从我的观点来看
function programs_management()
{
        if($this->input->get("enable_recomandation"))
        {
        //  $this->programs_management->recomandation((int)$this->input->get("programs"), ($this->input->get("recomandation")=="1")?"1":"0");
            $data_for_update = array(
                    'recomandation' => ($this->input->get("recomandation")=="1")?"1":"0",             
                    );
                    $this->db->update('programs',$data_for_update,array('program_id' => $this->input->get("programs")));

        }
}



 function enable_recomandation($value, $row = NULL)
    {
// or For AJAX some solution need
//     return "<form action='' method='post'>
//                <input onClick='document.getElementById('row').value=this.value' type='radio' name='recom' value='activ'>Activ<br>
//                <input onClick='document.getElementById('row').value=this.value' type='radio' name='recom' value='inactiv'>Inactiv
//            </form>";


      if($value=="1")
            return '<a href="'.base_url().'/admin/programs_management/?recomandation=0&program_id='.$row->program_id.'" >Active</a>';
        else
            return '<a href="'.base_url().'/admin/programs_management/?recomandation=1&program_id='.$row->program_id.'" >Inactive</a>';
    }

或者有人可以帮助替代,如何使用AJAX做到这一点?

1 个答案:

答案 0 :(得分:1)

function programs_management()
{
        if ($this->input->get("recomandation"))
        {
            //  $this->programs_management->recomandation((int)$this->input->get("programs"), ($this->input->get("recomandation")=="1")?"1":"0");
            $data_for_update = array(
            'recomandation' => ($this->input->get("recomandation") == "y") ? "1" : "0",
            );
            $this->db->update('programs', $data_for_update, array('program_id' => $this->input->get("program_id")));

        }
}


function enable_recomandation($value, $row = NULL)
{

if ($value == "1")
    return '<a href="' . base_url() . 'admin/programs_management/?recomandation=n&program_id=' . $row->program_id . '" >Active</a>';
else
    return '<a href="' . base_url() . 'admin/programs_management/?recomandation=y&program_id=' . $row->program_id . '" >Inactive</a>';
}