Answer the question
In order to leave comments, you need to log in
How wrong (terribly) is my organization on the site?
Hello! A week ago, I started to make a small project, 50-60% is already ready, and after seeing what happens, I became a little scared.
I have a few doubts and fears:
1. I make layout without a framework. Did some routing (if you can call it that). In general, in fact, the site will not be very large, at most 10 pages. The essence of the router is as follows:
switch ($_SERVER['REQUEST_URI']) {
case '/':
include_once 'modules/main.php';
break;
case '/deposit':
include_once 'modules/load.php';
break;
case '/account':
include_once 'modules/account.php';
break;
case '/faq':
include_once 'modules/faq.php';
break;
default:
echo "404";
}
Answer the question
In order to leave comments, you need to log in
Look better https://www.youtube.com/playlist?list=PLE20id3DjfF...
The author, analyzes how to write your own framework. Based on these videos, you can understand how routing works in popular frameworks, template engines, mvc, etc.
Read the basics of MVC, I think many questions will disappear at once.
//можно подключить в отдельном файле....
function error_404() {
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
header("Status: 404 Not Found");
include(ERRORS_PATH.'/404.php');
die();
}
switch (true) {
case $_SERVER['REQUEST_URI']==='/':
include_once 'modules/main.php';
break;
case strpos($_SERVER['REQUEST_URI'],'/deposit')===0:
include_once 'modules/load.php';
break;
...
...
default:
error_404();
}
instead of a switch / case, it is better to use an array of the key-value type, it is also easier to programmatically increase (routing for 20 paths with a switch will be a so-so solution), and you can process it in any way, because it's data, not a condition. But in general, you were rightly told - see ready-made solutions, there are many of them, from simple to very fancy ones.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question