I am new in PHP and have read about MVC. Currently, I am not using any frameworks and will like to know how can I push data from the controller to the view.
Background:
- htmlForm1.php -> Get inputs and pass data to DoWork.php to process
- DoWork.php -> Do work and pass to htmlForm2.php to display
- htmlForm2.php -> Display results
I understand that I obtain the values (from htmlForm1.php) in DoWork.php through _GET. My question is how do I get the values (from DoWork.php) in htmlForm2.php?
I have thought of using session, but is this the only solution? I do not require this data to be persistent after htmlForm2.php
The only information, that controller should be pushing to the view instance, would be user input (and even then only in rare cases).
Instead the views should be requesting information from model layer through the services. The controller is mostly responsible for changing the state of mode layer, based on user input. That also should be done through services.
To accomplish this the controller and view must have access to the same model layer. This is usually done by injecting some sort of
ServiceFactoryin both instances. The factory then makes sure that every service is instantiated only once, without making the code dependent on global state.