Answer the question
In order to leave comments, you need to log in
I comprehend MVC, to start learning it will do?
I am studying the separation of the controller, logic and template in order to turn my educational project from a single php + html + mysql mess into something more or less decent, in the controller, to simplify understanding, I began to write like this:
<?php
if(isset($_GET['value']) && $_GET['value'] == 1 ){
include '../model/model_1.php';
include '../view/view_1.php';
}
else {
include '../model/model_default.php';
include '../view/view_default.php';
}
?>
Answer the question
In order to leave comments, you need to log in
Everything is good in the lessons.
OOP isn't that hard, it just seems that way until you try it.
Look at these lessons, everything is clear here (IMHO) - click
It will do, but it’s better to scatter it immediately into separate blocks (even without OOP) - at least you will see that there are Models, Views, Controllers and routing:
<?php
function response($view, $model) {include $view;include $model;}
$models = array(
'default' => '../model/model_default.php',
'some' => '../model/model_1.php'
);
$views = array(
'default' => '../view/view_default.php',
'some' => '../view/view_1.php'
);
function controller($page) {
GLOBAL $models, $views;
switch ($page) {
case 'firstPage':
response($models['some'], $views['some']);
break;
case 'contacts':
response($models['default'], $views['some']);
break;
case 'default':
response($models['default'], $views['default']);
break;
}
}
function router(){
if (isset($_GET['value']) && $_GET['value'] == 1) {
controller('firstPage');
} else {
controller('default');
}
}
router();
In principle - yes, if you do not take into account OOP, then it's good. It is better to make a lot of controllers (on each page), and they are loaded in index.html, depending on the parameters.
And that's... learn OOP! It is almost easy, and the profit is big.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question