Hi everyone,
First sorry about my english.
Second i want to say that that is my first time working with POO and with MVC.
And because of that im realy lost where i need to put my code (in Controller or in Model).
To me because of my background with old php it is dificult to understand that.
here is a example of JogoController:
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
'placar'=>$this->alteraPlacar($id),
));
}
public function alteraPlacar($id)
{
$placar = null;
$model = $this->loadModel($id);
if ($model->id_time1==Yii::app()->user->id_time || $model->id_time2==Yii::app()->user->id_time)
{
$placar = JogoPlacar::model()->find(
'id_jogo=:idJogo AND id_user=:idUser', array(':idJogo'=>$model->id, 'idUser'=>Yii::app()->user->id));
if ($placar == null)
{
$placar = new JogoPlacar;
$placar->id_jogo = $model->id;
$placar->id_user = Yii::app()->user->id;
}
}
if(isset($_POST['JogoPlacar']))
{
$placar->attributes=$_POST['JogoPlacar'];
if($placar->save())
$this->redirect(array('/jogo/view','id'=>$model->id));
}
else{
return $placar;
}
}
All this work fine, but i have the feeling that is not the best way to do it.
Can someone pls help me work in this exemple to make it better.
I appreciate any help.
Thanks,
Lucas