//controller
if(Model_Character::is_owned($this->user_id, $character_id))
{
//edit the character
}
else
{
Session::set_flash('error', 'This character is not yours!');
Response::redirect('/characters');
}
//model
public function is_owned($id, $character_id){
$characters = Model_Character::find()
->related('simpleusers_api')
->where('t1.user_id', '=', $id)
->get();
$flag = false;
foreach($characters as $character)
{
if ($character->character_id == $character_id)
{
$flag = true;
}
}
return $flag;
}
ession::set_flash('error', 'This character is not yours!');
Response::redirect('/characters');
It looks like you're new here. If you want to get involved, click one of these buttons!