Title after the id in the url gives 404 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Title after the id in the url gives 404 (/showthread.php?tid=41965) |
Title after the id in the url gives 404 - El Forum - 05-22-2011 [eluser]Dennizzz[/eluser] Sorry for the maybe confusing title, but had to come up with something describing the situation right? :p So i just started learning CI and like everyone i started making a blog looking at the tutorial and than adjusting it too how i code. I like my urls clean and starting with the id first so thats what im going for, something like http://example.com/blog/3434/this-is-my-title-of-this-blog/ so started using the htacces, got it working, and started using the routes wich is working. Now whenever i call the blog using blog/3434/ it works fine, but whenever the url has the title in it, it gives me a 404 page. Controller Code: class Blog extends CI_Controller { The specific model Code: function showSingleblog() { And the route Code: $route['blog/:num'] = "blog/view"; Tried all sorts of different searching terms on the forums and wiki but could not find anything, hope someone can help me with this. edit: Sorry posted in the wrong forums, tought i was in the right one. Title after the id in the url gives 404 - El Forum - 05-22-2011 [eluser]InsiteFX[/eluser] Code: $route['blog/:num'] = "blog/view/$1"; InsiteFX Title after the id in the url gives 404 - El Forum - 05-22-2011 [eluser]Dennizzz[/eluser] Im sorry i should have posted it, but i did actually already tried that, with and without en closing slash, but it does not solve up the problem. Title after the id in the url gives 404 - El Forum - 05-22-2011 [eluser]InsiteFX[/eluser] Should be 3 not 2 Code: // 1=controller - 2=view - 3 $1 Title after the id in the url gives 404 - El Forum - 05-22-2011 [eluser]Dennizzz[/eluser] No its 2, because of the route file there is no view in the url. Title after the id in the url gives 404 - El Forum - 05-22-2011 [eluser]theprodigy[/eluser] Quote: Have you tried adding a parameter to the view function (and pass it to the model) rather than trying to use url segments? Code: class Blog extends CI_Controller { Title after the id in the url gives 404 - El Forum - 05-22-2011 [eluser]Dennizzz[/eluser] No i had not, i have tried it now but it still wont work when the title is in the url, without it works fine. Title after the id in the url gives 404 - El Forum - 05-22-2011 [eluser]theprodigy[/eluser] Are you using the title for anything other than 'clean urls'? Do you actually have a stub field in the db that you are querying against? It doesn't appear to be so, which is why I am asking. Code: function view($blog_id, $blog_title) { //add $blog_title as parameter as well and maybe alter your $route Code: $route['blog/:num/:any'] = "blog/view"; Title after the id in the url gives 404 - El Forum - 05-23-2011 [eluser]Dennizzz[/eluser] The title is used for displaying on the page itself, as for the clean url. I now tried altering the route line as u suggested, which did the trick on his own, much appreciated of thinking allong with me on this one! I also removed the $blog_id from the the view function, because i did not quite understand it, but does a parameter in the view function also get passed allong from the url? |