风快走了 发表于 2016-5-31 02:14:45

方法内ID值的传递问题。

//显示填写表单
    public function add(){
   $id=$this->uri->segment(4);
   $data['id']=$id;
   $data['title']=$this->db->select('title')->from('qtype')->where('id',$id)->get()->result_array();
    /* echo $data['title']['title'];      
   p($data);die;*/
   $this->load->view('index/add.html',$data);

    }
现在根据表单验证情况,没通过返回到add方法中。
public function addpost(){

            $id=$this->input->post('id');
            $title=$this->input->post('title');
            $content=$this->input->post('content');
            $address=$this->input->post('address');
      //执行表单验证
      /*
       * 载入验证类
       */
       $this->load->library('form_validation');
       $this->load->helper('form');
       $this->form_validation->set_rules('title','标题','required');
       $this->form_validation->set_rules('content','内容','required');
       $this->form_validation->set_rules('content','发生地点','required');
       if($this->form_validation->run()==FALSE){
      
            $this->add();

       }

ID值怎么传过去呢?

Aloghli 发表于 2016-5-31 09:01:54

public function add($id){}这样写      $this->add($id);   就行了
页: [1]
查看完整版本: 方法内ID值的传递问题。