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

查看:182
本文介绍了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');

db查询需要这两个字段。

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)

问题是如何传递两个值到 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天全站免登陆