如何获取管理员ID并在整个应用程序中使用它?

时间:2017-06-08 16:15:52

标签: php twitter-bootstrap codeigniter-3

在codeigniter中,我想在DB表中需要的admin Id上添加产品。当管理员登录他的ID时必须抓住。无论何时何地需要Id,它都必须可用。

这是我的 VIEW          

    <?php echo form_open_multipart('admin/add_product');?>

<!------------------Product Name------------------------>
 <div class="row form-group">
       <div class="col-sm-10"> 

      <label>Product Name: *</label>
  <?php echo form_input(['name'=>'name','class'=>'form-
    control','placeholder'=>'Product name..','value'=> 
   set_value('name')])?> 
      <div>
          <?php echo form_error('name');?>
      </div>
      </div></div>
      <!------------------Product Cat---------------------------->
 <div class="row form-group">
       <div class="col-sm-12">
  <label>Category: *</label> <br>
 <select class="selectpicker" name="pro_cat_id">
<option label="Select Category">Category</option>
<?php
 foreach($product_cat as $cat)
  {?>
  <option value="<?= $cat['pro_cat_id'] ?>"><?= $cat['category'] ?>
 </option>
     <?php }?>
</select>
 <div>

   <!------------------Product Price---------------------------->
 <div class="row form-group">
       <div class="col-md-10">
    <label>Product Price: *</label>
<?php echo form_input(['name'=>'price','class'=>'form-

   control','placeholder'=>'Product Price..','value'=> 
     set_value('price')])?>


   <div>
    <?php echo form_error('price');?>
 </div>
  </div></div>


     <!------------------Product Location---------------------------->
      <div class="row form-group">
       <div class="col-md-10">
      <label>Product Location: *</label>
    <?php //echo form_input(['name'=>'location','class'=>'form-
        control','placeholder'=>'Product Location'])?>

       </div></div>

    </div></div>
        <!-----------End of body---------------->
       </div>
     <div class="modal-footer">
     <input name="" type="submit" value="ADD" class="btn btn-success">

     </div>

         <?php echo form_close();?>
     </div>
 </div>
  </div>

这是我的控制器

            function add_product(){  
       $data['product_size'] = $this->show->show_product_size();
      $data['product_cat']= $this->show->show_product_category();
      $data['product_color'] = $this->show->show_product_color();
   $data['pr']= $this->show->show_provider();

    $post= $this->input->post();
  $ =this->form_validation->set_error_delimiters("<p class='text-danger'>","
  </p>");
if($this->form_validation->run('add_product')){
if($this->add->add_product($post)==TRUE){

     $this->db->close();
     $this->session->set_flashdata('success','Product has been added 
       successfully');
    return redirect('admins/pages/add_product_page');
     //$this->load->admin_template('admin/add_product',$data);

}
}
else
{
    $this->session->set_flashdata('failled','Sorry, fail to add product');
    //return redirect('admins/pages/add_product_page');
    $upload_error= $this->upload->display_errors();

     $this->load->admin_template('admin/add_product',$data);
   }
  } 

1 个答案:

答案 0 :(得分:0)

使用此查询,最好在您的控制器中:

$this->session->userdata('id');