I have built an MVC php application and was wondering, if instead of having to write out a large amount of html and set the data, could I not just have all this html (with some php) in a separate file and just require it?
For example:
$test = '<div>
Test content
<div>More content</div>
</div>';
$APP->Template->setData('test', $test, FALSE);
Instead could I not just use:
$test = require("includes/content.php");
$APP->Template->setData('test', $test, FALSE);
Would this be considered as bad practice? It just seems that by requiring files, it can shorten the length of controllers.
Would be good to get anybodies advice on this matter.
It depends on where you do the includes: if you do them in your Model, that would be wrong. However, in the view it would be alright.
It is a matter of separation of concerns: the model is the backbone of your application, while the view is responsible for displaying results from the model.
I do not see, how includes would shorten the length of the controller.