Model and Controller issue

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

If you’ll explain us what’s happening there, then we can probably help you ;)

Sorry…

I had 3 tables (username, jogo, jogoplacar) where the table jogo has all the information about a game(soccer game) and the table jogoplacar has the score that the user think will happen for a individual game.

So the table jogoplacar has two FK (id_user, id_jogo).

What i need to do is:

  • when a user select a game(jogo), before render it to check if one of the teams of this game is my time

  • them select jogoplacar(my score of this game)

  • and if that dont exist i create a new instance

After that i render a view with the info about the game and the form input for the score where i can update the result.

I dont know if that was confusing, but my english is not good.