I am new to PHP. I am using a MVC project as an example, and I noticed that each time a submit button is pressed my controller is called. The issue with this is that it creates a new model every time the button is pressed.
To fix this, I used a hidden field to check if the button has already been pressed. If it has, then I do not instantiate a new Model, otherwise I do. Code from controller is below:
 //code listed below is in the controller which is called each time button
 //has been pressed...
 $myModel;//used to access model and its functions from controller
 if(isset($_POST['has_started'])) 
 {
     //stores some logic that uses $myModel variable
     playingGame();
 }
 else
 {
   echo "just starting...";
   $myModel=new HangManModel();
   startGame($myModel);
 }
This seems to work, BUT then when playingGame() is called it tells me I cannot use $myModel and its functions because it was not declared, or it is a non-object. How can I fix this? Thanks for the help!
 
     
    