duanlu2935 2016-12-31 00:14
浏览 59
已采纳

在codeigniter的控制器中更改了获取html链接的问题

I was using ajax calls. when I click on the edit link it would pop up a modal with all the information. I now want to change it, so that it goes to an edit page instead. The part I need changed is the onclick on the edit link bellow in the code from edit_record to instead call a function in my controller called edit. Any help would be appreciated I spent quit a long time trying different ways and keep getting errors.

Here is the controller function code called ajax_list

public function ajax_list()
{
    $list = $this->your_table->get_datatables();
    $data = array();
    $no = $_POST['start'];
    foreach ($list as $your_table) {
        $no++;
        $row = array();
        $row[] = $your_table->name;
        $row[] = $your_table->title;
        $row[] = $your_table->body;


        //add html for action
        $row[] = '<a class="btn btn-sm btn-link " href="javascript:void()" title="Edit" onclick="edit_record('."'".$your_table->id."'".')"><i class="glyphicon glyphicon-pencil"></i> Edit</a>
                  <a class="btn btn-sm text-warning" href="javascript:void()" title="Hapus" onclick="delete_record('."'".$your_table->id."'".')"><i class="glyphicon glyphicon-trash"></i> Delete</a>';

        $data[] = $row;
    }

    $output = array(
                    "draw" => $_POST['draw'],
                    "recordsTotal" => $this->your_table->count_all(),
                    "recordsFiltered" => $this->your_table->count_filtered(),
                    "data" => $data,
            );
    //output to json format
    echo json_encode($output);
}

Here is the code in my your_controller called edit

//loads a single record with the data dispalyed for editing
    function edit($id)
    {
        $data['r']=$this->your_table->get_by_id($id);
        $this->load->view('pages/edit', $data);
    }


        //updates data in the database from the edit function
    function save_edit()
    {
        $id=$this->input->post('txtid');
        $data=array(
            'name'=>$this->input->post('txtname'),
            'title'=>$this->input->post('txttitle'),
            'body'=>$this->input->post('txtbody'));


        $this->db->where('id', $id);
        $this->db->update('your_table', $data);
        redirect('your_controller/index');
    }
  • 写回答

1条回答 默认 最新

  • doude4924 2016-12-31 14:10
    关注

    If your controller is called "edit" and your method has the same name, just change to:

    //add html for action
        $row[] = '<a class="btn btn-sm btn-link " href="/edit/edit/'.$your->table->id.'" title="Edit"><i class="glyphicon glyphicon-pencil"></i> Edit</a>
                  <a class="btn btn-sm text-warning" href="javascript:void()" title="Hapus" onclick="delete_record('."'".$your_table->id."'".')"><i class="glyphicon glyphicon-trash"></i> Delete</a>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看