如何将加载的数据从视图返回到控制器,以便在另一个函数上重用


How to get a loaded data from view back to controller to be reused on another function?

我正在编码点火器中研究 CRUDS,并成功地显示数据库中的数据并将数据插入数据库中。我不确定我在这里哪里出错了,但我需要重用我在视图页面中加载的 ID 以在数据库中对其进行编辑,我使用以下代码加载了数据(它是 foreach 循环的一部分(,我被要求编辑问题

<div class="gbItem">
                    <a href="#"></a>
<a href="#" class="pull-left">
                      <img alt="image" class="img-circle" src="<?php echo base_url(); ?>/public/img/profile.jpg">
                    </a>
                    <div class="gbItemBody clearfix">
                      <input type="hidden" name="user_id" value="<?php echo $value->user_id  ;?>">
                      <div class="pull-left">
                        <i class="fa fa-circle gbDeactivate"></i>
                        <a><strong>
                          <?php echo $value->user_firstname;?>
                          <?php echo $value->user_lastname;?>
                        </strong></a>
                        <br>                            
                          <strong>
                            Campaign 1
                          </strong>                            
                      </div>  
                      <div class="pull-right">
                        <span class="gbDeactivate pull-right">Idle</span><br>
                        <span class="pull-right">Skill Level 4</span>                           
                      </div>              
                    </div>
                </div>

我需要将其返回到控制器中以在名为

public function update()
{
$user['user_name'] = $this->users_model->get_by_id("i want it here");
//codes here
}

谁能帮我?

这将解决您的问题:

public function update()
{
$id = $this->input->post('user_id');
$user['user_name'] = $this->users_model->get_by_id($id);
//codes here
}
朋友我会

帮助你在控制器中,添加数据时,使用此$this->insert_id((;//将帮助您获取插入的 id。

$insert=$this->tender_model->form_insert($data);
 $id = $this->db->insert_id();
//then pass this id to view page

喜欢这个

$this->load->view('moderator/managetender',$id);

在视图页面中,我们可以提供编辑操作的链接,并且可以$id与该函数一起传递在视图中

 <a href="<?php echo base_url() . 'moderator/Tender/editdetails/'.$id?>"><button class="btn btn-primary pull-right" style="margin-right: 5px;"><i class="fa fa-edit"></i> Edit Details</button></a>