Dynamic Routes |
[eluser]Thiago Leao[/eluser]
I needed some help. I am making a news system, and would like the url appear the title of the news. How can I do this? example, www.mypage.com/my-news-for-today Actually, I do links instead of validating the ID, I would for the title. It would be something. thanks guys!
[eluser]Tpojka[/eluser]
I am not quite sure what you are looking for. I am asuming you want that clicking on: Code: http://www.mypage.com/my-news-for-today Is that case?
[eluser]Thiago Leao[/eluser]
I want to validate the news for the title. when I click on the news, you see a url with the news!!! thanks
[eluser]Tpojka[/eluser]
Can you show in what exact form you have URL of news now?
[eluser]Thiago Leao[/eluser]
VIEW Code: <li> CONTROLLER Code: function visualizar($title) MODEL Code: function verNoticia($title) I want to see the url with the title that is in the database!! understand?
[eluser]Tpojka[/eluser]
Ok. This like: You need one more column in table `noticias` called slug. When making input of news you will make slug input with your title using CI native function url_title(). You can check it on URL helper link in user guide. Also, I am thinking about you would need one more CI native function called convert_accented_characters() that is located in TExt helper in user guide. So for now you have stored slug in your DB table. When you calling data from table, you won't call it by Title reference. You will do that now by slug reference. To avoid uri segments news/visualize, you will need to make remaping in route.php file (config folder). So in your case it could be something like: route.php Code: $route['(:any)'] = "news/visualize/$1"; Code: function verNoticia($title) Code: function visualizar($slug) Code: <li>
[eluser]Tpojka[/eluser]
Edit: Server is dissallowing me to edit post in anti-flood kind matter. In model, argument of method should also be $slug. And in view link should be base_url($listar_noticias[$j]->slug) P.S. CroNiX was bit faster.
[eluser]Thiago Leao[/eluser]
[quote author="CroNiX" date="1382657048"]Use a wildcard route. http://ellislab.com/codeigniter/user-gui...uting.html[/quote] Has somehow, without me having to create a new column in the table? Since I already have enough record in the news! thanks!
[eluser]Tpojka[/eluser]
It is called DB planning before application is made. There is no other way. You can't get Pesca en el otoƱo from pesca-en-el-otono. Machine doesn't know where to put accent, what is capital letter etc. Code: function titles2slugs($titles){ //you will select all titles from DB table Also, it would be smart to make $slug array in localhost where you can increase php script execution time for this loop. Rest is up to you. |
Welcome Guest, Not a member yet? Register Sign In |