Use title in URL |
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?
I'm not a professional, certainly are better solutions, but after much research I found the solution below, valid for CI3:
The model: function get_name() { $string = $this->uri->segment(3); $array=explode("8801",$string); $id = ($array[1] / 9); $this->db->where('id', $id); $query = $this->db->get('names'); return $query->result(); } Below, I'm associating names/albums: function get_albuns() { $string = $this->uri->segment(3); $array=explode("8801",$string); $idx = ($array[1] / 9); $sql = ("SELECT A.*, PA.* FROM albuns A, players_albuns PA WHERE PA.player_id=$idx AND PA.album_id = A.id ORDER BY ano, posodr, album_id ASC"); $query = $this->db->query($sql); return $query->result(); } The view: foreach ($name as $row); $playerid = $row->id; $name = $row->name; $linkname = (9 * $playerid); $str = convert_accented_characters( $name); $urln = $url_title = url_title($str, '-', TRUE); As my website is only local, I have great freedom in testing solutions, but of course, within my limitations, which are not few.Below, some results: echo "<a href='/allmedia/names/$url_title-wd8801$linkname'>$name</a>"; http://localhost/allmedia/names/ella-fit...wd88011395 echo "<a href='/music/album/$record-wd8803$linkrec'>$title</a>"; http://localhost/music/album/ella-fitzge...d880312705
@omid-student,
> $url_title = url_title($title, 'underscore'); I would advise against using underscore in the URL_title and use a hyphen instead. I forgot the reason since it was a long time ago since I followed a SEO recommendation. Perhaps a search could find the reference. I have a joke site with about 3,500 jokes and each joke in the joke table has a unique $row->title which has served well for SEO purposes and to reduce script to find the associated table record.
Here is what I am doing with my current projects.
Code: $title = $this->request->getVar("title"); $current_title is stored in the slug column. This is my helper's function. Code: //get Master Entry Slug And this is how I am calling from views Code: <a href="<?php echo base_url(); ?>/<?php echo get_masterentry_slug($entry['id']); ?>/<?php echo $entry['slug']; ?> "> And this is working in my case. I have referenced the above code because I have previously faced the same issue, I can store slug in abc/cde/def in a column but can not call from routes, routes ignore / I think .correct me if I am wrong. Thanks
I use Codeigniter 3
i used url_title already but what's happening for ? or / or \ characters? (02-19-2020, 08:30 AM)omid_student Wrote: I use Codeigniter 3Here's a list of approved characters in URLs: https://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid
@omid_student,
I just checked on my joke site and found that if have two fields, one the actual title and the other table->XRL which is the URL. The joke site was written using CI 2.xxx a long time ago and been updated numerous times. I just checked and found this URL search appears as top of the first page of a Google search: "a-love-story-like-this-almost-brings-tears-to-my-"
(02-19-2020, 09:12 AM)John_Betong Wrote: @omid_student,You say when i insert record data into database,same time add url readable string in database?
@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. |
Welcome Guest, Not a member yet? Register Sign In |