A
A
Anton R.2019-08-13 16:26:11
PHP
Anton R., 2019-08-13 16:26:11

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';
}
?>

That is, if the condition is 1 -> we load such Models and Views, if there are no conditions -> we load the default ones, and so on. So far without classes, because in all the lessons IMMEDIATELY the code for some reason goes to OOP, which I consider quite difficult to start.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikita Kolesnikov, 2019-08-13
@NikitOS_MV

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

H
hack504, 2019-09-10
@hack504

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();

S
Sergey Litvinov, 2019-08-13
@SeApps

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 question

Ask a Question

731 491 924 answers to any question