在codeigniter控制器中,将所有控件名称作为列名称

时间:2016-05-14 06:13:20

标签: php codeigniter

这是我的观点

<form class = 'form_container left_label' id = 'addproduct_form1111', enctype = 'multipart/form-data' action="admin/product/UpdateProduct" onkeypress="return event.keyCode != 13;" method="POST">
                 <input type="hidden" name="latitude" id="latitude" value="<?php echo $lat;?>" />
                <input type="hidden" name="longitude" id="longitude" value="<?php echo $lang;?>" />
                <input type="hidden" name="prdiii" id="prdiii" value="<?php if(!empty($product_details)){ echo trim(stripslashes($product_details->row()->id)); } else { echo "0";}?>" />
      <div id="tab1">
        <ul class="tab-areas1">
             <li>
            <div class="form_grid_12">
              <label class="field_title" for="user_id">Property Owner Name <span class="req">*</span></label>
              <div class="form_input">
              <?php 
              if(!empty($userdetails)){ echo '<select name="user_id" >';
                foreach($userdetails->result() as $user_details){


              ?>

              <option value="<?php echo $user_details->id;?>" <?php if(!empty($product_details)){ if($user_details->id==$product_details->row()->OwnerId){echo 'selected="selected"';} } ?>><?php echo ucfirst($user_details->firstname).' '.ucfirst($user_details->lastname);?></option>

             <?php  
                } echo '</select>';
             } ?>


              </div>
            </div>
          </li> 
          <li>
            <div class="form_grid_12">
              <label class="field_title" for="product_title">Title <span class="req">*</span></label>
              <div class="form_input">
              <?php if(!empty($product_details)){  $Valid = trim(stripslashes($product_details->row()->id)); } else {  $Valid=0;}?>
                <input name="product_title" id="product_title" type="text" tabindex="1" class="required large tipTop" title="Please enter the Property name" onchange="javascript:AdminDetailview(this,document.getElementById('prdiii').value,'title');"  onkeypress="return runScript(event);"  onkeydown = "return (event.keyCode!=13);"
                value="<?php if(!empty($product_details)){ echo trim(stripslashes($product_details->row()->product_title)); }?>"/>

              </div>
            </div>
          </li>
          <li>
            <div class="form_grid_12">
              <label class="field_title" for="price">Room Type</label>
              <div class="form_input">
                STANDARD  <br>


              </div>
            </div>
          </li>


         <li>
            <div class="form_grid_12">
              <label class="field_title" for="price">Price per day<span class="req">*</span></label>
              <div class="form_input">
                <input type="text" name="price" id="price" tabindex="9" class="required large tipTop" title="Please enter the property price" value="<?php if(!empty($product_details)){ echo trim(stripslashes($product_details->row()->price)); }?>"  onchange="javascript:PriceInsert(this.value,document.getElementById('prdiii').value,'price');"/>


              </div>
            </div>
          </li>

          <li>
            <div class="form_grid_12">
              <label class="field_title" for="price1">Price per day for single occupacy<span class="req">*</span></label>
              <div class="form_input">
                <input type="text" name="st_price1" id="st_price1" tabindex="10" class="required large tipTop" title="Please enter the property price 1" value="<?php if(!empty($product_details)){ echo trim(stripslashes($product_details->row()->st_price1)); }?>"  onchange="javascript:PriceInsert(this.value,document.getElementById('prdiii').value,'st_price1');"/>


              </div>
            </div>
          </li>

          <li>
            <div class="form_grid_12">
              <label class="field_title" for="price">Price per day for double occupacy<span class="req">*</span></label>
              <div class="form_input">
                <input type="text" name="st_price2" id="st_price2" tabindex="11" class="required large tipTop" title="Please enter the property price 2" value="<?php if(!empty($product_details)){ echo trim(stripslashes($product_details->row()->st_price2)); }?>"  onchange="javascript:PriceInsert(this.value,document.getElementById('prdiii').value,'st_price2');"/>


              </div>
            </div>
          </li>

          <li>
            <div class="form_grid_12">
              <label class="field_title" for="price">Price per day for tripal occupacy<span class="req">*</span></label>
              <div class="form_input">
                <input type="text" name="st_price3" id="st_price3" tabindex="12" class="required large tipTop" title="Please enter the property price" value="<?php if(!empty($product_details)){ echo trim(stripslashes($product_details->row()->st_price3)); }?>"  onchange="javascript:PriceInsert(this.value,document.getElementById('prdiii').value,'st_price3');"/>


              </div>
            </div>
          </li>


          <li>
            <div class="form_grid_12">
              <label class="field_title" for="price">Room Type<span class="req">*</span></label>
              <div class="form_input">
                PREMIUM 
              </div>
            </div>
          </li>


        <li>
            <div class="form_grid_12">
              <label class="field_title" for="price">Price per day for single occupacy<span class="req">*</span></label>
              <div class="form_input">
                <input type="text" name="pr_price1" id="pr_price1" tabindex="13" class="required large tipTop" title="Please enter the property price 1" value="<?php if(!empty($product_details)){ echo trim(stripslashes($product_details->row()->pr_price1)); }?>"  onchange="javascript:PriceInsert(this.value,document.getElementById('prdiii').value,'pr_price1');"/>


              </div>
            </div>
          </li>

          <li>
            <div class="form_grid_12">
              <label class="field_title" for="price">Price per day for double occupacy<span class="req">*</span></label>
              <div class="form_input">
                <input type="text" name="pr_price2" id="pr_price2" tabindex="14" class="required large tipTop" title="Please enter the property price 2" value="<?php if(!empty($product_details)){ echo trim(stripslashes($product_details->row()->pr_price2)); }?>"  onchange="javascript:PriceInsert(this.value,document.getElementById('prdiii').value,'pr_price2');"/>


              </div>
            </div>
          </li>

          <li>
            <div class="form_grid_12">
              <label class="field_title" for="price">Price per day for tripal occupacy<span class="req">*</span></label>
              <div class="form_input">
                <input type="text" name="pr_price3" id="pr_price3" tabindex="15" class="required large tipTop" title="Please enter the property price" value="<?php if(!empty($product_details)){ echo trim(stripslashes($product_details->row()->pr_price3)); }?>"  onchange="javascript:PriceInsert(this.value,document.getElementById('prdiii').value,'pr_price3');"/>


              </div>
            </div>
          </li>

          <li>
            <div class="form_grid_12">
              <label class="field_title" for="price">Room Type<span class="req">*</span></label>
              <div class="form_input">
                EXECUTIVE 
              </div>
            </div>
          </li>


        <li>
            <div class="form_grid_12">
              <label class="field_title" for="price1">Price per day for single occupacy<span class="req">*</span></label>
              <div class="form_input">
                <input type="text" name="ex_price1" id="ex_price1" tabindex="16" class="required large tipTop" title="Please enter the property price 1" value="<?php if(!empty($product_details)){ echo trim(stripslashes($product_details->row()->ex_price1)); }?>"  onchange="javascript:PriceInsert(this.value,document.getElementById('prdiii').value,'ex_price1');"/>


              </div>

               <input type="text" name="prsdfsdice" id="prdsfsdfice" />
                <input type="text" name="abc" id="abc" />
            </div>
          </li>

          <li>
            <div class="form_grid_12">
              <label class="field_title" for="price">Price per day for double occupacy<span class="req">*</span></label>
              <div class="form_input">
                <input type="text" name="ex_price2" id="ex_price2" tabindex="17" class="required large tipTop" title="Please enter the property price 2" value="<?php if(!empty($product_details)){ echo trim(stripslashes($product_details->row()->ex_price2)); }?>"  onchange="javascript:PriceInsert(this.value,document.getElementById('prdiii').value,'ex_price2');"/>


              </div>
            </div>
          </li>

          <li>
            <div class="form_grid_12">
              <label class="field_title" for="price">Price per day for tripal occupacy<span class="req">*</span></label>
              <div class="form_input">
                <input type="text" name="ex_price3" id="ex_price3" tabindex="18" class="required large tipTop" title="Please enter the property price" value="<?php if(!empty($product_details)){ echo trim(stripslashes($product_details->row()->ex_price3)); }?>"  onchange="javascript:PriceInsert(this.value,document.getElementById('prdiii').value,'ex_price3');"/>
              </div>
            </div>
          </li>


           <li style="display:none">
            <div class="form_grid_12">
              <label class="field_title" for="description">Deal End Date</label>
              <div class="form_input">
                <input type="text" name="deal_end_date" id="deal_end_date" tabindex="9" class="required large tipTop datepicker" title="Please select deal end date" value="<?php if(!empty($ProductDealPrice)){ echo trim(stripslashes($ProductDealPrice->row()->deal_end_date)); }?>"  onchange="DealPriceInsert(this.value,'deal_end_date');"/>
              </div>
            </div>
          </li>



          <li>
            <div class="form_grid_12">
              <div class="form_input">
                <input type="button" class="btn_small btn_blue nxtTab" id="nextImage" tabindex="9" value="Next"/>
              </div>
            </div>
          </li>
        </ul>
      </div>
      </form>

这是控制器

public function UpdateProduct(){ 
    /*image upload end */
    //echo "<pre>"; print_r($this->input->post()); 

    $room_name = $this->input->post('room_name');
    $ame_name = $this->input->post('ame_name');
    //print_r($ame_name);
    //$r_val

    if ($this->checkLogin('A') == ''){
        redirect('admin');
    }else {

        $product_data=array();
        $facility_list=array();

        $product_id = $this->input->post('prdiii');

        if ($product_id == ''){
            $inputArr = array(

            );
        }else {
            $inputArr = array(

            );
        }

        $dataArr = array_merge($inputArr,$product_data,$facility_list);


        $condition = array('id' => $product_id);
        $this->product_model->commonInsertUpdate(PRODUCT,'update',$excludeArr,$dataArr,$condition);

        echo $this->db->last_query();die;

        $Attr_val_str = '';


        $this->setErrorMessage('success','Host added successfully');


        redirect('admin/product/display_product_list');
    }

}

此模型功能

public function commonInsertUpdate($table='',$mode='',$excludeArr='',$dataArr='',$condition=''){
    $inputArr = array();
    foreach ($this->input->post() as $key => $val){
        if (!in_array($key, $excludeArr)){
            $inputArr[$key] = $val;
        }
    }
    $finalArr = array_merge($inputArr,$dataArr);

    if ($mode == 'insert'){
        return $this->db->insert($table,$finalArr);
    }else if ($mode == 'update'){
        $this->db->where($condition);
        return $this->db->update($table,$finalArr); 
    }
}

我不知道控制器功能如何将所有表单控件名称作为列并发送到模型函数。请帮助。

错误:这是代码模型功能得到所有控件名称,但我不需要所有我需要一些特定列。

UPDATE `fc_product` SET `latitude` = '28.44886970520019500', `longitude` = '77.09976959228516000', `prdiii` = '9', `user_id` = '38', `product_title` = 'STARiHOTELS Guragaon', `price` = '25000.00', `st_price1` = '0.00', `st_price2` = '0.00', `st_price3` = '0.00', `pr_price1` = '25000.00', `pr_price2` = '35000.00', `pr_price3` = '40000.00', `ex_price1` = '0.00', `prsdfsdice` = '', `abc` = '', `ex_price2` = '0.00', `ex_price3` = '0.00', `deal_amount` = '', `deal_start_date` = '', `deal_end_date` = '', `status` = 'on', `meta_title` = '', `meta_keyword` = 'ghhj', `meta_description` = ' hjghghj', `userID` = '0' WHERE `id` = '9'

0 个答案:

没有答案