如何在代码点火器中使用表类手动添加删除和更新等链接


how to add links like delete and update manually using table class in codeigniter

>我成功地使用 codeigniter 表类创建表,但不知道如何像链接一样手动添加值,我成功地将所有值从后端显示到我的表,但不知道如何限制特定值视图以及如何添加链接,例如删除更新到我的表代码 1:这是我的控制器功能,当我单击管理面板中的查看用户链接时打开

    public function viewusers()
    {
        $this->load->model('insert_model');
         $im['pic']=$this->insert_model->image_fetc();

            // print_r($aaa); die();
            //  $data['aa'] = "sd"; 
            //$data['books'] = $this->abc();
            $data['books'] = $this->insert_model->pagination();
             //print "<pre>";print_r($data);die();
             $this->load->view('header_view',$im);
             $this->load->view('navside_view_admin');
             $this->load->view('admin_view', $data);
    } 

Code2:这是我的模型(插入模型),其中有分页函数,我正在使用代码点火器的页面类来创建表

    public function pagination(){
        //$this->load->model('insert_model');
         //$data ['query'] = $this->insert_model->view_data(); 
        $this->load->library('table');
        // Load Pagination
        $this->load->library('pagination');
        $total_row = $this->db->count_all("register");
        // Config setup
        $config['base_url'] = base_url().'index.php/welcome/viewusers';
        $config['total_rows'] = $total_row;
        $kk=$config['use_page_numbers'] = TRUE;
        $rpp =$config['per_page'] =15;
        $nop=ceil($total_row/$rpp);
        // I added this extra one to control the number of links to show up at each page.
         $config['num_links'] = $nop;

        // Initialize
        $this->pagination->initialize($config);
        // Query the database and get results
        // Here we add the limit and the offset
        // The second parameter is the limit, since we are showing
        // 10 per page, the limit should be 10
        if($this->uri->segment(3)){
            $page = ($this->uri->segment(3)) ;
            }
            else{
            $page = 1;
            }
        $offset = ($rpp*$page)-$rpp;
        $qry = $this->db->get('register',15, $offset);
        // Create custom headers
       $header = array('id','username','lastname','email' , 'password', 'image','status','operations');
        $tmpl = array ( 'table_open'  => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">' );
       // foreach($qry as $rows)
       /* {
            $links  = anchor('controller/edit/'.$row->id ,'Edit');
        }*/
$this->table->set_template($tmpl);
 /*$this->table->add_row(
        $row->id,
        $row->fname,
        $row->lname,
        $row->email,
        $row->pass,
        $row->image,
           //add the links you created to the last row, corresponding to your 'Links' Header
    );*/
         //Set the headings
        $this->table->set_heading($header);
        // Load the view and send the results
       // print_r($offset);die();
     /*   if($offset == 0)
        {   
        return $data['books'];
        }
        else
        {
       //$data['books'] = $this->abc();
            $im['pic']=$this->insert_model->image_fetc();
        $this->load->view('header_view',$im);
         $this->load->view('navside_view');
           $this->load->view('admin_view', $data);
            }
       // print_r($data); die();
    }*/return $qry->result_array();
}}

Code3:这是我的管理视图,我在其中显示从表中获取的数据,该数据是使用 Codeigniter 的表类生成的,我不知道如何在此表中手动添加删除或更新等链接,以及如何在表中显示数据库中的受限值,但首先解决显示链接的问题,例如删除更新到表列......

 <?php

 if(isset($books)){
  echo $this->table->generate($books); ?>
    <?php echo $this->pagination->create_links(); }?>

我已经在我的控制器中做了这件事,你可能会从中得到一些提示。

public function index() {
    $this->load->library('table');
    $data_rows = $this->my_model->get();
    $tmpl = array('table_open' => '<table id="sample_1" class="table table-striped table-bordered table-hover dataTable" aria-describedby="sample_1_info">');
    $this->table->set_template($tmpl);
    $this->table->set_heading('Name', 'Type','Reason', 'Status', 'Approval');
    foreach ($data_rows as $row) {
        $approvals = anchor('my_url' . $row->id, 'Approve', array('class' => 'btn green mini')) . " ";
        $approvals .= anchor('my_url' . $row->id, 'Refuse', array('class' => 'btn red mini'));
        //I have added all the columns with two extra columns named approvals links in it.
        $content = array($row->name, $row->type, $row->reason, $status, $approvals);
        $this->table->add_row($content);
    }
    $leaves_table = $this->table->generate();
    $this->load->view('layouts/header');
    $this->load->view('layouts/sidebar');
    $this->load->view('leaves/lists', array('leaves_table' => $leaves_table));
    $this->load->view('layouts/footer');
}