提出されたものと同じタイトルとプラットフォームを持つゲームがデータベースにあるときはいつでも(dbに提出する前に)チェックしたいと思います。
私はこのコントローラーを持っています:
public function addGame($id = null) { // ID is for children games
$this->load->library(array('images','form_validation'));
$this->load->helper('form');
$this->load->model('contrib_model');
$this->form_validation->set_rules('gameTitle', 'Tytuł gry', 'required|callback_checkGamePlatform');
if($this->form_validation->run() == FALSE) {
$data['title'] = 'Dodaj grę';
$data['genres'] = $this->contrib_model->getGenres();
$data['platforms'] = $this->contrib_model->getPlatforms();
$data['developers'] = $this->contrib_model->getDevelopers();
$this->template->load('template','theme/contribute/addGame',$data);
} else {
$data['submit'] = $this->contrib_model->insertGame();; //submits data
$this->load->view('theme/contribute/emptyPage', $data); //loads view
}
}
public function checkGamePlatform() {
$platform = $this->input->post('gamePlatform');
$game = $this->input->post('gameTitle');
$q = $this->contrib_model->checkGame($game,$platform);
echo $q;
if($q === '0') {
$this->form_validation->set_message('checkGamePlatform','gra istnieje');
}
}
そしてこのモデル:
function checkGame($name,$platform) {
$q = $this->db->get_where('games',array(
'name' => $name,
'plat' => $platform
));
return $q -> num_rows();
}
問題は、それがまったく機能しないことです。私が間違っていることは何ですか?