将数据保存在没有闪存数据的codeigniter中

时间:2015-05-21 08:14:21

标签: php codeigniter

我在codeigniter中创建了一个管理系统,用于从特定供应商的数据表中加载数据库中的数据。当用户点击任何这些数据行时,他将导航到每个供应商的公司产品。我的问题是,我想找到一个会话或其他东西,以便在页面重新加载时保留先前所选行的数据。目前我正在使用flashdata,但当我返回步骤或返回上一页时,数据库中的所有数据都会消失。我想要的是即使我正在重新加载页面,或者如果我回过头来保留我的数据。 那是我的控制者:

  public function __construct() {
    parent::__construct();
    $this->load->library('form_validation');
     $this->load->model('dash_match_model');
     $this->session->keep_flashdata('supplier_id');
     $this->session->keep_flashdata('segment');
     $this->session->keep_flashdata('class');
      $this->session->keep_flashdata('commodity');
     $this->load->library('session');
    $this->load->helper('url');

}

public function index() {
   $arr['page']='dash1';
   $user_id = $this->session->userdata('id');

   $supplier = $this->dash_match_model->dash_present_all_suppliers($user_id);
   $arr['dash_present_all_suppliers'] = $supplier;
    $this->load->view('clients/clDashboard',$arr);

}

public function select_supplier() 
{

    $supplier_name = $this->input->get('name', TRUE);


    $supplier_sel = $this->dash_match_model->selected_supplier_id($supplier_name);
    foreach ($supplier_sel->result() as $row){

        $this->session->set_flashdata('supplier_id', $row->supplier_id);
    }

    $selected_supplier = $this->dash_match_model->unspsc_matched_skus($this->session->flashdata('supplier_id'));
    $arr['dash_present_all_selected_suppliers'] = $selected_supplier;

    $this->load->view('clients/unspscSegment', $arr);
}

public function select_segment(){
    $segment = $this->input->get('segment', TRUE);
    $supplier_id = $this->session->flashdata('supplier_id');

    $this->session->set_flashdata('segment', $segment);
    $segment_sel =$this->session->flashdata('segment');

$selected_segment = $this->dash_match_model->unspsc_class($supplier_id, $segment_sel);

    $arr['dash_present_all_selected_segments'] = $selected_segment;

    $this->load->view('clients/unspscClass', $arr);

}

public function select_class(){
    $class = $this->input->get('class', TRUE);
    $supplier_id = $this->session->flashdata('supplier_id');
    $segment_sel =$this->session->flashdata('segment');

    $this->session->set_flashdata('class', $class);
    $class_sel = $this->session->flashdata('class');

    $selected_class =$this->dash_match_model->unspsc_commodity($supplier_id, $segment_sel, $class_sel);

    $arr['dash_present_all_selected_class'] = $selected_class;

    $this->load->view('clients/unsspscCommodity', $arr);

这是我与供应商的第一个表格视图文件之一:

            <div class="row-fluid sortable">        
            <div class="box span12">
                <div class="box-header" data-original-title>
                    <div class="box-icon">
                        <a href="#" class="btn-setting"><i class="halflings-icon wrench"></i></a>
                        <a href="#" class="btn-minimize"><i class="halflings-icon chevron-up"></i></a>
                        <a href="#" class="btn-close"><i class="halflings-icon remove"></i></a>
                    </div>
                </div>
                <div class="box-content">
                    <table id="suppliertable" class="table table-striped table-bordered bootstrap-datatable datatable">
                      <thead>
                          <tr>
                              <th>Supplier</th>
                              <th>Open Range</th>
                              <th>Fill Content</th>
                              <th>Total Match</th>
                          </tr>
                      </thead>   
                      <tbody>
                      <?php foreach($dash_present_all_suppliers as $v): ?>
                              <tr>      
                                    <td class="center" style="color:#0c595b;"><a href="<?php  echo base_url(); ?>admin/dashboard1/select_supplier?name=<?php echo $v['supplierCompany']?>"><?php echo $v['supplierCompany']?> </a> </td>
                                    <td class="center">70%</td>
                                    <td class="center">12%</td>
                                    <td class="center">82%</td>
                            </tr>
                    <?php endforeach; ?>
                    </tbody>
                  </table>  
                </div>
            </div><!--/span-->

        </div>

1 个答案:

答案 0 :(得分:1)

而不是使用$this->session->flashdata()用户正常会话,即$this->session->userdata()来存储临时浏览数据并编写一个cron,它将在定期间隔或注销时删除此会话或任何所需的特定时间动作。

希望这会提供更好的方法,帮助您解决问题