如何在codeigniter中使用设定值功能设置值

时间:2016-04-20 05:46:21

标签: php codeigniter

<input type="hidden" name="template" value="<?php echo set_value   ('template',$temp); ?>" />


  public function index($id=NULL)
 {
    if(empty($id)){
     redirect('service');
    }else{
   $this->load->model('servicemodel');
$pro = $this->servicemodel->get_pro_info($id);  
if($pro){
    $this->load->helper('form');
        $data['temp']=$pro['0']['name'];
    $data['page']="buynow/userform";
    $this->load->view('buynow/paymentindia',$data);        }  


    public function user_validation()
{
    $this->load->library('form_validation');
    $this->form_validation->set_error_delimiters("<p class='text-danger'>","</p>");
    if ($this->form_validation->run('uservalidation')){

         // validation success
    }else{

          $this->load->helper('form');
    $this->load->view('buynow/paymentindia',$data);
    }
  }

我想在设定值中填充数据,未定义的$temp

会出现错误

我的表单功能不同,但验证功能不同,当我们在验证$temp显示未定义变量时发生任何错误。

1 个答案:

答案 0 :(得分:0)

假设这是你的控制器

public function registerForm(){
  //you have to pass a value to $temp
  $data[temp] = '101';
  $this->load->view('register',$data);
}

现在您将获得register.php视图文件中的值

验证失败后,您没有将任何值传递给$ temp

使用以下代码

public function user_validation()
{
  $this->load->library('form_validation');
  $this->form_validation->set_error_delimiters("<p class='text-danger'>","</p>");
   if ($this->form_validation->run('uservalidation')){
     // validation success
   }else{
      // you have to pass value again to $temp
      $data['temp'] = $this->input->post('template');
      $this->load->helper('form');
      $this->load->view('buynow/paymentindia',$data);
   }
 }