D
D
DiaTMs2019-01-02 23:04:45
PHP
DiaTMs, 2019-01-02 23:04:45

How to properly implement mvc?

Good day. I've watched a lot of tutorials and read enough books, but still don't understand the concept of mvc. Let's say we have several files with .html or .php resolution. If the file exists, the browser shows it; if not, it gives an error about the absence of the file. The problem is the following. I have seen 3 implementations and with which I do not entirely agree.

1) Make one entry point to the site through mod_rewrite so that all requests go to index.php
.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php


What is the minus !-d file structure can be viewed

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php


Now it's better, but if you access, for example, /app/controllers/Route.php It

will be an error because the file is connected in a different path from index.php

as it should be

../views/error/404page.php

actually

app/views/error /404page.php

2) It is not clear why create 2 directories

-app
models
views
controllers
-public
css
js
fonts
icons
images
index.php

If you redirect to public/index.php the app directory will be closed, but how then to make ajax requests and receive responses in the form of json to the client?

3) RewriteRule (.*) index.php?url=$1 [L,QSA]

Parsing from $GET['url'] is a disadvantage for me, since the site will be accessible both by /news and by index.php?url=news.

How to implement mvc so that you can get rid of errors + send ajax requests and receive responses?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
grinat, 2019-01-02
@DiaTMs

You have some class App that starts when requested, and it contains a Router that processes the request, parses / siski or index.php?url=siski and decides which controller to call: SiskiContoller.php or SiskiAjaxController.php when the request comes to the controller , it takes data from the Siski model, SiskiContoller re-renders the data to the siski file that is in the views, SiskiAjaxController makes json_encode for the data and displays it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question