need help for pass variables |
[eluser]Unknown[/eluser]
Hi everyone :-) I need help with my project. I have a news system on my website and each news has a url like that: http://mywebsite/news/news-title I use the "news-title" segment for retrieve the news from the database but it's not good if two news have the same title. So, I want to retrieve the news with the news ID but I also want to keep an URL like http://mywebsite/news/news-title AND not like http://mywebsite/news/news_id OR http://mywebsite/news/news-title/news_id My question is : Is there any way to pass the news_id variable from news links to the news controller without using url? Thanks a lot for you help. ps: sorry for my very bad english
[eluser]NBrepresent[/eluser]
Hi Orbital, Unfortunately no... You need to either force unique slugs (news-title in your example) when the news article is first entered into your system, or be stuck with passing the id of the article in the url. I like the way Lifehacker does it: http://lifehacker.com/5109739/kidzui-is-...-interface
[eluser]sofwan[/eluser]
You can still pass news-title in your url and add some codes to find certain id, for example like this : $this->db->where('title_news',$this->uri->segment(2)); $this->db->where('id','1'); $hasil=$this->db->get('tbl_news'); $row=$hasil->row(); echo $row->news; Hopefully it's helpful.
[eluser]bitist[/eluser]
[quote author="NBrepresent" date="1230725751"] I like the way Lifehacker does it: http://lifehacker.com/5109739/kidzui-is-...-interface[/quote] Other solutions could be: http:// lifehacker.com/5109739-kidzui-is-a-kid-friendly-web-interface http:// lifehacker.com/kidzui-is-a-kid-friendly-web-interface-5109739
[eluser]NBrepresent[/eluser]
Here's the way I like to handle it in the model: Code: function get_show($slugid) { $slugid can either be an integer (the primary key of the thing you want to retrieve) or you can match against the slug, if you have things set up so that the slug is guaranteed to be unique. |
Welcome Guest, Not a member yet? Register Sign In |