Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Validation 如何使用CodeIgniter回调检查播放器是否已被选中_Validation_Codeigniter - Fatal编程技术网

Validation 如何使用CodeIgniter回调检查播放器是否已被选中

Validation 如何使用CodeIgniter回调检查播放器是否已被选中,validation,codeigniter,Validation,Codeigniter,我想知道是否有人能帮我。我试图确保,当一名经理在他的球队中挑选球员以确认足球成绩时,他只能挑选一名球员一次 因此,我的验证回调从这里开始: $this->form_validation->set_rules('P1', 'The Home Team cannot play with less than 7 players', 'trim|required|callback_player1_check'); 然后我有了这个回调函数: function callback_player1

我想知道是否有人能帮我。我试图确保,当一名经理在他的球队中挑选球员以确认足球成绩时,他只能挑选一名球员一次

因此,我的验证回调从这里开始:

$this->form_validation->set_rules('P1', 'The Home Team cannot play with less than 7 players', 'trim|required|callback_player1_check');
然后我有了这个回调函数:

function callback_player1_check()
{
    if ($this->fixtures_model->callback_player1_check()== TRUE)
    {
        $this->form_validation->set_message('P1', 'Player already selected');
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}
function callback_player1_check() {
$player_id1 = $this->input->post('P1');
$player_id2 = $this->input->post('P2');


if ($player_id1 == $player_id2)
                {
    return TRUE;
}       
}
然后,此回调函数链接到此模型函数:

function callback_player1_check() {
$player_id1 = $this->input->post('P1');
$player_id2 = $this->input->post('P2');


if ($player_id1 == $player_id2)
                {
    return TRUE;
}       
}
所以我现在要做的就是检查玩家1(P1)和玩家2(P2)是否是同一个玩家。这是行不通的。如果我能解决这个问题,那么我需要检查所有玩家,以确保某个玩家只被选中一次


任何帮助都会很好!非常感谢。

您不需要在回调函数前面加上单词
callback\uuu

function player1_check() {
    $player_id1 = $this->input->post('P1');
    // etc
应该可以

编辑
关于他们的命名约定,请参阅。

我应该澄清一下-如果添加了前缀,它将不起作用,因为CI会自动查找前缀。我已经更新了我的帖子,因为它不清楚。现在都修复了。谢谢你的指导罗斯:)我在我的项目的其他地方也用过同样的东西,只是这是漫长的一周!谢谢你的帮助。