Codeigniter 将 2 个参数传递给回调 [英] Codeigniter passing 2 arguments to callback

查看:29
本文介绍了Codeigniter 将 2 个参数传递给回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发布具有两个名为id"和url"的字段的表单后,我有以下代码:

After posting a form having two fields named 'id' and 'url' I have the following code:

$this->load->library('form_validation');
$this->form_validation->set_rules('id', 'id', 'trim|xss_clean');
$this->form_validation->set_rules('url', 'url|id', 'trim|xss_clean|callback_url_check');

数据库查询需要两个字段.

A db query needs both fields.

函数 url_check($str, $id) 被调用,但在这种情况下,'id' 的值始终为 0.

The function url_check($str, $id) is called but in this case 'id' always has the value 0.

如果我只是这样做:

$this->form_validation->set_rules('url', 'url', 'trim|xss_clean|callback_url_check');

然后调用 url_check($str) 一切正常.

And call url_check($str) everything's working as it's is supposed to do.

问题是如何将两个值传递给 url_check($str, $id)?

The question is how do I pass two values to the url_check($str, $id)?

推荐答案

可以直接使用$this->input->post:

You can use $this->input->post directly:

function check_url() {
   $url = $this->input->post('url');
   $id = $this->input->post('id');

   // do some database things you need to do e.g.
   if ($url_check = $this->user_model->check_url($url, $id) {
       return TRUE;
   }
   $this->form_validation->set_message('Url check is invalid');
   return FALSE;
}

这篇关于Codeigniter 将 2 个参数传递给回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆