To begin with, I'm a newbie, made just one small php projector in a "procedural" way, and now I'm looking for a way to jump over the huge gap that separates procedural programming from OOP. Most of the information on MVC provides that I have already moved across this abyss, and therefore practically useless. I have found the only article so far that explains as primitively as possible, starting with the basics, and I try to remake my project by analogy under MVC.
There was a problem - in my project the logic is a little more complicated than in the "business card site", and the article does not answer the question of where and how it is "more difficult" to implement.
In the mentioned article, the View
class View
extremely simple: the View->Generate($view_content, $view_template)
makes require $view_template.'.php'
, inside the template, in turn, the only place is require $view_content.'.php'
.
Depending on the controller / method, I need to insert into the template in several places. The question is how to implement it correctly?
The solution I propose is to cram in constructions like include $block[0].'.php'
into the main template (do not require
it so that it doesn’t curse when there is no file), then fill this array with filenames in acc. models ...
Immediately there are questions:
if I don't need to insert in this view, say,
$block[0]
- how will theinclude
directive be executed? Will she try to access the file (in this case,NULL
)? And in general, is it right to do so? ( upd: of courseif (isset($block[0])) { include $block[0].'.php'; }
- but it turns out that some of the logic is transferred to the form: /)How to deal with blocks that you want to use several times? For example, I have a simple mold there for filtering output from the base, but on one page should it filter suppliers, and on the other, goods in stock? To implement through a class?