RE: Use title in URL - omid_student - 02-25-2020
(02-25-2020, 03:59 AM)John_Betong Wrote: @omid_student,
> You say when i insert record data into database,same time add url readable string in database?
It was a long time ago and I thought it would cater for some title not exactly matching the Xrl field. I think the url_title(...) function caters for at least 99% of cases and better to slightly adjust the title instead of having two separate field. Yes i know but i cannot decode it
I think when i insert product to database,same time make url title for each product
RE: Use title in URL - zahhar - 02-25-2020
(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).
RE: Use title in URL - omid_student - 02-25-2020
(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?
RE: Use title in URL - John_Betong - 02-25-2020
@omid_student
> I thought that i encode and decode it for search in database
Here's an AJAX search demo with source that searches for words in the database:
https://johns-jokes.com/downloads/sp-e/jb-ajax-search/
RE: Use title in URL - omid_student - 02-25-2020
(02-25-2020, 07:55 AM)John_Betong Wrote: @omid_student
> I thought that i encode and decode it for search in database
Here's an AJAX search demo with source that searches for words in the database:
https://johns-jokes.com/downloads/sp-e/jb-ajax-search/
Thanks
RE: Use title in URL - advmihir123 - 02-28-2020
(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?
|