使用模型框编辑值

时间:2015-06-08 12:02:56

标签: php twitter-bootstrap codeigniter

我想使用bootstrap模型编辑表格行....当我点击编辑按钮时,它会打开一个名称为designttion的模型框,我想编辑 ..但是当我点击按钮时只有modalbox显示但没有显示记录... 请解决我的问题

控制器

public function edit_desig(){
        $this->load->model('designation_model');
        $this->designation_model->edit_designation($id);
    }

模型

public function edit_designation($id){
        $query=$this->db->get_where('designation',array('desig_id'=>$id));
        return $query->result();
    }

我的观点

<div id="myModal" class="modal fade" id="editdesigymodal" role="dialog">
            <div class="modal-dialog">

            <!-- Modal content-->
                <div class="modal-content">
                    <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">Edit Designation</h4>
                    </div>
                    <div class="modal-body">
                        <input id="editdesignnation" type="text" class="form-control" placeholder="Enter here" />
                    </div>
                    <div class="modal-footer">
                        <button type="button" onclick="edit_designation()" class="btn btn-success" data-dismiss="modal">Edit</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>

            </div>
        </div>

            <div class="container">
                <div class="row">
                    <div class="col-lg-12 col-sm-12">
                        <table class="table table-bordered table-striped">
                            <thead>
                                 <tr>
                                    <th>#</th>
                                    <th>Designations</th>
                                 </tr>
                            </thead>
                            <tbody>

                                <?php  print_r($designation); $i=1;foreach($designation as $desig): ?>
                                      <tr>
                                           <td><?php echo $i; ?></td>

                                           <td><?php echo $desig['name']; ?></td>

                                            <td><a href="<?php echo base_url('index.php/designation/delete_designation/'.$desig['dkey']);?>"><input type="button" value="Delete" class="btn btn-danger"/></a>
                                            <td class="numeric"><a id= "<?php echo $desig['dkey']; ?>"  onclick="edit_designation('<?php echo  $desig['dkey']; ?>')" data-target="#myModal" data-toggle="modal" href="<?php echo base_url().'index.php/designation/edit_desig'; ?>"><button class="btn blue" type="button">Edit</button>

                                      </tr>
                            <?php $i++;endforeach;?>

1 个答案:

答案 0 :(得分:3)

您需要将查询结果传递给视图

<强>控制器

public function edit_desig(){
        $this->load->model('designation_model');
        $designation=$this->designation_model->edit_designation($id);// assing your query result to your variable
        $data['designation'] = designation;// pas your variavle to data arrray
        $this->load->view('view_name', $data);// load your view with array
    }

根据您的视图代码,您需要在模型中以数组形式获取数据

<强>模型

public function edit_designation($id){
        $query=$this->db->get_where('designation',array('desig_id'=>$id));
        return $query->result_array();// change this to array
    }