A
A
Alexander Yakovlev2015-02-13 16:29:42
symfony
Alexander Yakovlev, 2015-02-13 16:29:42

SEF URL's in Symfony2. How to drag from the database by id, and display the CNC?

Good day, friends. In the process of developing a custom (freelance) project on sf2, it became necessary to properly deal with the implementation of beautiful URLs for both humans and search engines.
The bottom line is this. According to the customer's request, the URLs should look like this:
audio-mastering-online.com/all-online-mastering-st... - main page
audio-mastering-online.com/all-online-mastering-st... - where namePage section of the site where you can select a search criterion for all companies that exist on the site. Whether it is a search by country in the countries section, or a search by selected parameters in the parameters section.
Currently, all companies by country are searched by country name.
http://audio-mastering-online.com/all-online-maste...
That's not good, of course. It is best to search the database by id.
With parameters, things are a little more complicated.
company-name.com/all-company-name-list/parameters (cutting from the TOR)
Actually, the question is: How to organize routing in sf2 in order to get everything from the database by id, while displaying the SEF URL.
PS I am from sf2 to you. The type of urls is not ironclad, I can discuss any options with the customer and convince him to do it the right way.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Yakovlev, 2015-02-14
@maches

Indeed, the need for this has disappeared. He moved his convolutions and found a solution to his problem in a different way. In general, you can make a slug on regexp (I found a live example on stack overflow ). Perhaps someone will help.

R
Ruslan Kvashnin, 2015-02-14
@RussellKvashnin

No way. Yes, and there is no need for this.
In the essence of the page, a field is added - an additional unique identifier (slug is called bourgeois).
It is this parameter that comes in the request, and it is for it that you are looking for in the database.
Quite a good solution.

A
Anton, 2015-02-14
Semenov

Of course, the question is strong))) Ruslan answered everything correctly, but if you are already sawing someone else or there is no desire to rewrite part of the code where id is already used, then:
Offhand, something like create a special field where to translate the page title into cnc ()
for example, they pulled it out of the database like this (ideally, they were going to insert it into the database)
id=567
title=I post a super topic
discr=This post is about a super topic
body=Here is all the crap html and pictures, etc., etc.
Well, take the title, google a function something like CyrToLat + replacing spaces to "_" and either add to the database or replace it with .htaccess for 301
so that the result would be something
....
$chpu_title = CyrToLat ($result->title);
$db->add_field_to_table($table, $chpu_title)->where(id=$result->id);
....
so that the field appears in the database
chpu_title=ya_post_super_tema
And then whatever you want, if you define it by id, then substitute chpu_title or already form links by taking chpu_title instead of id.
In general, it’s kind of strange ... such a question about such a framework causes dissonance.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question