我想在不同的页面显示更新表单意味着不同的视图如何在ci中做?

时间:2015-08-10 06:01:03

标签: php codeigniter

这是我的控制器update.php

 <?php
         class Update extends CI_Controller{

        function __construct(){
       parent::__construct();
         $this->load->model('update_model');
          }



function show_subcategory_id()
{
 $id = $this->uri->segment(4);
 $data['subcategory'] = $this->update_model->show_subcategory();
 $data['category']=$this->update_model->show_category();
 $data['single_subcategory'] = $this->update_model-

   >show_subcategory_id($id);
  $this->load->view('admin/esub', $data);
       }


       function update_subcategory_id1() {
       $id= $this->input->post('did');
         $data = array(
       'namesubcategory' => $this->input->post('dname'),
        'urlsubcategory' => $this->input->post('durl'),
        'idcategory' => $this->input->post('parent_menu'),
                );
   $this->update_model->update_subcategory_id1($id,$data);
   $this->show_subcategory_id();
   }

    }
      ?>

这是模型update_model.php

     <?php

       class Update_model extends CI_Model{

      function show_category(){
       $query = $this->db->get('category');
       $query_result = $query->result();
         return $query_result;
         }

           function show_subcategory(){
            $query = $this->db->get('subcategory');
             $query_result = $query->result();
             return $query_result;
                   }

               function show_subcategory_id($data){
              $this->db->select('*');
                $this->db->from('subcategory');
               $this->db->where('idsubcategory', $data);
                $query = $this->db->get();
               $result = $query->result();
              return $result;  
                 }

        function update_subcategory_id1($id,$data){
          $this->db->where('idsubcategory', $id);
             $this->db->update('subcategory', $data);  
                 }

                 }

                 ?>

这是查看update_view.php

                        <ol>
                    <?php foreach ($subcategory as $student): ?>
                        <li><a href="<?php echo base_url() . 
           "admin/update/show_subcategory_id/" . $student->idsubcategory; ?
             >"><?php echo $student->namesubcategory; ?></a></li>
                    <?php endforeach; ?>
                </ol>

                 <?php foreach ($single_subcategory as $student): ?>
                    <p>Edit Detail & Click Update Button</p>

                    <form method="post" action="<?php echo base_url() .
                    "admin/update/update_subcategory_id1"?>">
                        <label id="hide">Id :</label><br/> 
                        <input type="text" id="hide" name="did" value="<?php
                      echo $student->idsubcategory; ?>"><br/>      

                        <label>Name :</label><br/> 
                        <input type="text" name="dname" value="<?php echo
                          $student->namesubcategory; ?>"><br/>    

                        <label>url :</label><br/> 
                        <input type="text" name="durl" value="<?php echo
                           $student->urlsubcategory; ?>"><br/>

                         <label>Parent Menu :</label><br/> 
                        <select name="parent_menu">
                         <?php foreach ($category as $s):?>
                        <option value="<?php echo $s->idcategory;?>">
                        <?php echo $s->namecategory; ?>
                        </option>
                        <?php endforeach; ?>
                        </select>
                        <input type="submit" id="submit" name="dsubmit" 
                          value="Update">
                    </form>

                <?php endforeach; ?>

这工作正常,但我希望在不同的视图页面中显示子类别名称结果和更新表单......是否可能.. ??如何做到这一点?

1 个答案:

答案 0 :(得分:1)

                <select name="city_id">

            <?php

            foreach ($records_city as $row) { 

            if(isset($arrSelectCity[$row->city_id])) {

            ?>

            <option value="<?php echo $row->city_id; ?>" selected="selected" ><?php echo $row->city_name; ?></option><?php 
            }
            else{

            ?><option value="<?php echo $row->city_id; ?>" > <?php echo $row->city_name; ?></option>

            <?php
            }   
            }
            ?></select>


            HEAR what i understand what u want is u have to show sub category name than foreach all
            the data of that category and then done it as i show you as above code that i got city 
            name.

如果您有任何查询,请重播我的评论????