2009-01-26 66 views
0

我正在使用CodeIgniter通过$_POST请求和我正在阅读的PHP页面将一些参数传递到我的PHP页面。

$foo = $this->input->post('myParam'); 

如果myParam参数存在于$_POST请求,则$foo将被分配的myParam值。如何检查myParam是否不通过请求$_POST

回答

4

我Google搜索'codeigniter输入帖子'。

第一个结果是this

从该文档:

$this->input->post('some_data'); 

该函数返回FALSE(布尔)如果你正试图 项目检索不存在。

所以,你需要做的:

if ($foo===false) { 
    // do something if it's not set 
} 
+0

非常感谢。有效。 – Veera 2009-01-26 13:27:11

0

我认为这样做是使用表单验证类来实现对数据预处理的最佳途径。这被记录在here

你会做这样的事情:如果验证失败,它会送你回表格,你必须用数据来重新填充它

function index() 
{ 
    $this->load->helper(array('form', 'url')); 
    $this->load->library('form_validation'); 

    $this->form_validation->set_rules('myParam', 'myParam', 'required'); 
      if ($this->form_validation->run() == FALSE) 
    { 
     $this->load->view('myform'); 
    } 
    else 
    { 
     $this->load->view('formsuccess'); 
    } 
} 

,有一种方法可以做到这一点(请参阅文档)。如果通过,你可以确定$this->input->post('myParam');将返回一个值。