-
zahhar
Member
-
Posts: 53
Threads: 1
Joined: Jan 2020
Reputation:
0
02-25-2020, 06:40 AM
(This post was last modified: 02-25-2020, 06:44 AM by zahhar.)
(02-25-2020, 04:05 AM)omid_student Wrote: Yes i know but i cannot decode it
I think when i insert product to database,same time make url title for each product
Why you need to decode it? There should not be a need for it. It would be bad design.
Your initial approach is almost fine:
PHP Code: $title = "Agile Digital Project Manager/£475 - 525 pd/6 months/London"; $url_title = url_title($title, 'underscore');
However, I would recommend to enrich it with 3 following items:
- Use minus (dash) sign as a separator insted of underscore - for SEO reasons
- Convert it lowercase as makes no sense to keep the case in URL (url_title() has 3rd param to cast to lowercase)
- Make it unique by combining with record unique ID (table ID will work fine)
So you will get:
PHP Code: $id = 12345; //it should come from your DB table record ID $title = "Agile Digital Project Manager/£475 - 525 pd/6 months/London"; $url_title = url_title($title, '-', TRUE)."-".$id;
//Output: //agile-digital-project-manager-475-525-pd-6-months-london-12345
This way you ensure each $url_title is unique, even when there are job ads with same titles (e.g. "Project Manager"). Then you store in DB both $title and $url_title, and update $url_title every time $title changes. And when/if you want to get $title by $url_title, you can do one SQL query ("where url_title = %s", $url_title).
-
omid_student
Omid Aghakhani
-
Posts: 381
Threads: 119
Joined: May 2015
Reputation:
0
02-25-2020, 06:56 AM
(This post was last modified: 02-25-2020, 06:56 AM by omid_student.)
(02-25-2020, 06:40 AM)zahhar Wrote: (02-25-2020, 04:05 AM)omid_student Wrote: Yes i know but i cannot decode it
I think when i insert product to database,same time make url title for each product
Why you need to decode it? There should not be a need for it. It would be bad design.
Your initial approach is almost fine:
PHP Code: $title = "Agile Digital Project Manager/£475 - 525 pd/6 months/London"; $url_title = url_title($title, 'underscore');
However, I would recommend to enrich it with 3 following items:
- Use minus (dash) sign as a separator insted of underscore - for SEO reasons
- Convert it lowercase as makes no sense to keep the case in URL (url_title() has 3rd param to cast to lowercase)
- Make it unique by combining with record unique ID (table ID will work fine)
So you will get:
PHP Code: $id = 12345; //it should come from your DB table record ID $title = "Agile Digital Project Manager/£475 - 525 pd/6 months/London"; $url_title = url_title($title, '-', TRUE)."-".$id;
//Output: //agile-digital-project-manager-475-525-pd-6-months-london-12345
This way you ensure each $url_title is unique, even when there are job ads with same titles (e.g. "Project Manager"). Then you store in DB both $title and $url_title, and update $url_title every time $title changes. And when/if you want to get $title by $url_title, you can do one SQL query ("where url_title = %s", $url_title).
Oh yes your solution is the best
I thought that i encode and decode it for search in database
But now with your solution,i encode it and save to database and search with it
Thanks
(02-25-2020, 06:40 AM)zahhar Wrote: (02-25-2020, 04:05 AM)omid_student Wrote: Yes i know but i cannot decode it
I think when i insert product to database,same time make url title for each product
Why you need to decode it? There should not be a need for it. It would be bad design.
Your initial approach is almost fine:
PHP Code: $title = "Agile Digital Project Manager/£475 - 525 pd/6 months/London"; $url_title = url_title($title, 'underscore');
However, I would recommend to enrich it with 3 following items:
- Use minus (dash) sign as a separator insted of underscore - for SEO reasons
- Convert it lowercase as makes no sense to keep the case in URL (url_title() has 3rd param to cast to lowercase)
- Make it unique by combining with record unique ID (table ID will work fine)
So you will get:
PHP Code: $id = 12345; //it should come from your DB table record ID $title = "Agile Digital Project Manager/£475 - 525 pd/6 months/London"; $url_title = url_title($title, '-', TRUE)."-".$id;
//Output: //agile-digital-project-manager-475-525-pd-6-months-london-12345
This way you ensure each $url_title is unique, even when there are job ads with same titles (e.g. "Project Manager"). Then you store in DB both $title and $url_title, and update $url_title every time $title changes. And when/if you want to get $title by $url_title, you can do one SQL query ("where url_title = %s", $url_title). Dy you can help me about reload config file when process is running?
-
John_Betong
Super Moderator
-
Posts: 588
Threads: 52
Joined: Oct 2014
Reputation:
4
-
omid_student
Omid Aghakhani
-
Posts: 381
Threads: 119
Joined: May 2015
Reputation:
0
-
advmihir123
Newbie
-
Posts: 1
Threads: 0
Joined: Feb 2020
Reputation:
0
(02-19-2020, 02:04 AM)omid_student Wrote: Hi
In my shop project,i need show product title in url
Example:
example.com/product/laptop sony/vio
laptop sony/vio is product tite
How do some sites show title in url and encode and decode it and search product?
In codeignter we can use below code
$title = "Agile Digital Project Manager/£475 - 525 pd/6 months/London";
$url_title = url_title($title, 'underscore');
But how do decode it?
|