在 Codeigniter 中,如何将第三个参数传递给回调(表单验证)?
我目前正在使用表单验证类(在 Codeigniter 上)并设置规则。
它的工作原理与两个参数类似(codeigniter.com/user_guide/libraries/form_validation.html ):
$this->form_validation->set_rules('username', 'Username', 'callback_test[abc]');
但是第三个参数呢?还有第四个……?是否可以?
I am currently using the Form Validation class (on Codeigniter) and setting rules.
It works like this with two parameters (codeigniter.com/user_guide/libraries/form_validation.html):
$this->form_validation->set_rules('username', 'Username', 'callback_test[abc]');
But what about a third parameter? And a fourth...? Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
它不是官方的,但可以用
“,”分割参数
It is not official but works
Split the parameter by ','
并非没有扩展系统表单验证类。有关如何实现此目的的信息,请查看此 文章。
或者,您可以使用以下方式访问回调函数中的 post 变量:
这可能会或可能不会帮助您。
Not without extended the system form validation class. For information on how to achieve this take a look at this article.
Alternatively you can access the post variables within your callback function using:
which may or may not help you out.
您可以使用数组来获取更多字段的更多参数,如下所示:
You can use Array for more parameters for more fields as like i did below:
您可以传递给规则
|callback_handle_is_unique_value_combinations[val1,val2]
比,
公共函数callback_handle_is_unique_value_combinations($str, $field)
{
$fields = 爆炸(',', $field);
$val1 = $fields[0];
$val2 = $fields[1];
然后你就做出了你的 cponarisons
You can pass to the rule
|callback_handle_is_unique_value_combinations[val1,val2]
than,
public function callback_handle_is_unique_value_combinations($str, $field)
{
$fields = explode(',', $field);
$val1 = $fields[0];
$val2 = $fields[1];
and then you made your cponarisons