1

我使用 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 做到这一点?

4

1 回答 1

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>';
}
于 2013-02-13T14:51:54.670 回答