S
S
Sergey Sulakov2015-03-11 23:59:46
PHP
Sergey Sulakov, 2015-03-11 23:59:46

CNC implementation by storing the "url"-"query" link in the database. What are your opinions?

Good time of the day!
Interested in the opinion of specialists in the implementation of CNC in this way:
All requests to the site are redirected to index.php according to the following rule:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L]

Example:
There is a line like site.com/notebook-lenovob550-da02ua, which turns into a line like
site.com/index.php?url=notebook-lenovob550-da02ua
then there is a query to the database to the table where the url-query links are stored
SELECT `query` FROM `url_to_query` WHERE `url` = 'notebook-lenovob550-da02ua' LIMIT 1

and a `query` of the form "view=good&good_id=34" is returned to the $query php variable (or 404 if the connection does not exist), then I parse the $query variable into the $_GET array
parse_str($query,$_GET);
, respectively, $_GET['view']='good ' and $_GET['good_id']='34'
then the output template good.php is connected - displaying the product page with id = 34.
What weaknesses can this method have, and does it even have a "right to life" at all?
ps If you explained crookedly - write questions in the comments. The opinion of experts is very important to me!

Answer the question

In order to leave comments, you need to log in

5 answer(s)
F
FanatPHP, 2015-03-12
@FanatPHP

Hell crutch.
Read about MVC

I
IceJOKER, 2015-03-12
@IceJOKER

Look at the architecture of frameworks, etc. because it's all there already.
Than to pull the database every time, I would make, for example, such a folder / file structure as in yii, depending on the URL, this or that class / method is called.
/catalog/view/1
create a folder and a file in it: controllers/CatalogController.php and add the view method there.
Then just parse the url and depending on whether there is a class/method or not, show or output an error.
you can write a simple router in a few minutes, explode with a slash, the first argument is the name of the class, the second is the name of the method, and everything else is passed to the method and voila
your method, which you described above, I would use to write, for example, blog posts and so on .
It all depends on the specific case.

A
asdz, 2015-03-12
@asdz

https://github.com/c9s/Pux

I
index0h, 2015-03-12
@index0h

If this is a slug, it makes sense to store it in the database, but be sure to cache it, as an option - directly give it to nginx from memcached. But this is provided that you have at least an n-level url. Those. if in your example
`site.com/ notebook -lenovob550-da02ua` the highlighted is the NotebookController - then ok. The fact is that CNC parsing is part of the work of any request, and if it is slow for you, the polar fox has already crept up and is waiting))

K
Kirill Saksin, 2015-03-12
@saksmt

Has the right to life in Redis / Memcached, provided that Notebook is a controller, and the rest is a slug.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question