title: PHP MVC: Share model between controller and view
body: <p>I'm working on my PHP (H)MVC project in which I separated the views from the controllers - as in the answer <a href="https://stackoverflow.com/questions/5863870/how-should-a-model-be-structured-in-mvc/5864000#5864000">How should a model be structured in MVC?</a>. Their relationship is 1:1, so they have the same "actions". Therefore, in bootstrap.php, after I instantiate them I call:</p>
  
  <pre><code>// ... Controller and view are already instantiated.
  call_user_func_array(array($controller, $actionName), $actionParameters);
  call_user_func_array(array($view, $actionName), $actionParameters);
  </code></pre>
  
  <p>Let's say that a controller and a view become, each of them, a model (domain object) as constructor parameter.
  Using <a href="https://github.com/rdlowrey/auryn" rel="nofollow noreferrer">Auryn</a> dependency injection container, I try to share the same instance of the model between the controller and the view, without instantiating it beforehand. E.g. before controller and view instantiation takes place in bootstrap.php.</p>
  
  <p>In his answer, tereško describes the use of a model/service factory. But as a "Note" he says:</p>
  
  <blockquote>
    <p>...A much better implementation would have the DI container (like
    Auryn) to create controllers and views, with only the required
    services, instead of using a factory.</p>
  </blockquote>
  
  <p>My question is: Can I implement this functionality without a model factory using the dependency injection container?
  I'm kind of stuck in this task and I don't really know if this is somehow possible.
  Thank you.</p>