How to create a page in MVC without creating a file?

Hello! Learn PHP and actually trying to make a simple website in MVC.

Interested in the question, as to do so would be in the database stored url e.g. "contacts", and when a person clicks on the links site.ru/contacts, loaded the content in the defaul template from the table in the database? Want to achieve a result on the similarity of WordPress, in the admin edit, everything is in the database.

I'm probably badly formulated question, but I'm trying to figure out how to do so to display page from database, url, content, SEO tags, etc., and not to create each time a file contacts.php
If you do not want to answer, as the type is elementary, etc., throw at least a link where I could learn how to do it.

PS Tried to Google, but nothing sensible in response is not received. It is not excluded that the query was wrong

Example in DB
5c9a5acfec496366572882.jpeg
March 19th 20 at 08:43
3 answers
March 19th 20 at 08:45
Solution
Between MVC and to "give different pages without creating a file" a huge gap.
Generation of dynamic pages not directly related to MVC, no. This is generally the basics of PHP.

You to MVC yet, don't go, you at least in procedural style, learn how to program.

Well, your question has more to do with routers:
Let's say you have a script index.php
which produces different content depending on the parameter $_GET['page']

<?php
include 'config.php';
$db= new PDO($dsn,$user, $pass, $opt);
$result=$db->prepare("SELECT content FROM table_name WHERE url=:url");
$result->execute(array(":url" => $_GET['page']));
$page=$result->fetchAll(PDO::FETCH_ASSOC);

print $page[0]['content'];



?>


connect to the database and get from database the desired article/page.

you can go to a different page, addressing the same script index.php but with different parameter GET:

site.ru/index.php?page=index
site.ru/index.php?page=contacts
site.ru/index.php

But in order to transform the URL in a normal form, there is the concept of CNC Chelovekovedenija.
To do this, the file is created .htaccess (if the server is apache2)
and for example with this content:

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /index.php?page=$1 [L]


This file tells the server that when accessing the website site.ru/contacts.html you will be redirected to index.php?page=contacts.

In the end we have a single point of entry to the site - index.php as you wanted.

The chew does not make sense - this topic is not for a toaster, it's absolutely fundamental.

Google:
CNC.

And only after learn how to work with .htaccess and the single point of entry you can think of routers, MVC, etc.

If you
Thank you for the very detailed response! I will explore! - alexandro_Crona8 commented on March 19th 20 at 08:48
@alexandro_Crona8, you need a dynamic header, a template where the meta tags will be loaded, for example suppose there is a function which argument will pull the desired content from the base cap. Not all caps, and dynamically changing content. - hanna68 commented on March 19th 20 at 08:51
@alexandro_Crona8that the answer once I have cut even at the bottom)

See above - I've amended the code sample for your particular case. This is a primitive, but an example. And it will work with your table that you provided above. Only need to change table_name to the name of the table and fill config.php - Dorris_Stanton88 commented on March 19th 20 at 08:54
@Dorris_Stanton88, thank you! Use your code to parse the subject) Well, the boys have thrown links, I will study!) - alexandro_Crona8 commented on March 19th 20 at 08:57
@hanna68, well, at the expense of meta tags so as an example, the very essence to a new page, not create a new file, since pages can be 100, and this is not reasonable, etc.

And so, thanks for the tip!) - alexandro_Crona8 commented on March 19th 20 at 09:00
March 19th 20 at 08:47
So Google "Make a blog in php". You should get
if very short (you can't do that, but if you want somewhere to start)
to redirect all requests processed by the file index.php (either htaccess or nginx settings)
further parasite the contents of $_SERVER['REQUEST_URI'] and depending on what You got make the appropriate query to the database and get the info
Want to achieve a result on the similarity of WordPress, in the admin edit, everything is in the database. Thanks for the reply, there is something to go by.

Why is it so impossible to do? And as it correctly to do?) - alexandro_Crona8 commented on March 19th 20 at 08:50
@alexandro_Crona8,
well, in principle the idea is correct all the major engines (including WordPress) and built another thing is how to work with it on and now newbies are starting to turn index.php in a zombie dinosaur. - Immanuel.Abshire commented on March 19th 20 at 08:53
@Immanuel.Abshire, starting with a zombie dinosaur, and continue to improve, to change, to normalize, rather than not doing anything and not knowing to throw all)

And to do everything beautifully and correctly, I think it is difficult and every programmer has their vision. As I am currently in error here decided to write. Well, from your answers I will have to start. - alexandro_Crona8 commented on March 19th 20 at 08:56
@Immanuel.Abshire, what's wrong with index.php ?

I have everywhere index.php - entry point. - Dorris_Stanton88 commented on March 19th 20 at 08:59
@Dorris_Stanton88,
Yes, all right, I just remember the first attempts and file swelled to hundreds of rows.
I mean it's not good to parse the queries in the index.php and directly access the global variable - Immanuel.Abshire commented on March 19th 20 at 09:02
@Immanuel.Abshireand clear)-so I think-I have in the index is called the class autoloader and a router. Think here is not so)) - Dorris_Stanton88 commented on March 19th 20 at 09:05
March 19th 20 at 08:49
If you take the concept briefly (diagram), then:

1. With CNC routed all url in index.php (via .htaccess)

2. Next, we will send a url variable to the database.

3. If an entry in the database is present, get all the information on the current page (the page type/template), headers, meta tags, text.

4. On the type page, connect the desired template .php and display all of our data. As a rule, differ only in the page templates, catalog, product.

A very simplified scheme.
@frances_Haag it's Very simplistic but very clear, thank you!) - alexandro_Crona8 commented on March 19th 20 at 08:52

Find more questions by tags PHP