Answer the question
In order to leave comments, you need to log in
How should the site work properly?
I create a site in PHP, I know this language at a level slightly higher than the basic one. But the question arose how to create your own website, how should it work?
There is such a concept:
The main page - index.php in it - header, footer, head and their content, there is also the main tag. But depending on the $_GET['page'] parameter, pages are connected to it.
The pages/ folder contains the pages that we include in index.php. If the get parameter is empty, then we include main.php (main page).
How well I use the language and work with the site. But there is also a title, keywords, description tag, and they also change depending on get. Not too many ifs?
Answer the question
In order to leave comments, you need to log in
Use a router, this is a good practice that has already become generally accepted.
https://github.com/nikic/FastRoute
The second is to use a template engine for pages (routes).
https://quasi-art.ru/library/it/5-top-php-template...
Well, the most important thing. Why don't you use any of the frameworks Yii , Laravel ?
It is not necessary to produce so many conditions. For example GET
, the parameter page
can be immediately supplied to the name of the included file. Just check if there is such a file first. Some kind of storage is needed for meta information. The principle is that do not check each parameter for existence. A very simple example: you create an array somewhere in the config with the required fields.
Then on the page in the right places display the values. And the point is that each page will fill this array in its own way. But keep in mind that more or less serious sites are not built this way. It's a completely different architecture.
$meta = ['title' => null, 'description' => null]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question