How to create routes using the MySQL database - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: How to create routes using the MySQL database (/showthread.php?tid=64805) |
How to create routes using the MySQL database - mauro269 - 03-28-2016 Hello guys, this is my first thread here in the CodeIgniter forum because I've started to develop my website with this fantastic framework since just 1 month. My learning curve is growing really fast but there are some issues that currently I'm not able to solve and I need your support. With the aim to create a dynamic website, I've created a controller named "rigatos" with inside a method named "cucuru". PHP Code: public function cucuru() { What I want to do is to have the same content of the "cucuru" method also for other methods, without the need to write other methods. What I have in mind is to create a table in my MySQL database (the name of the DB is "dork", the name of the table is "ogartab"). What I don't know is how to do this thing in the routes.php. What I know is that, if I write: $route['rigatos/carl'] = "rigatos/cucuru"; if I digit "localhost/rigatos/carl" the browser shows me the "localhost/rigatos/cucuru" page so it's ok. Now, what I'm trying to do is that typing "localhost/rigatos/bat" the browser should show me the content of "localhost/rigatos/cucuru". How can I do this? Do you have some suggestions? Thanks for your help. RE: How to create routes using the MySQL database - arma7x - 03-28-2016 $route['rigatos/(:any)'] = "rigatos/cucuru/$1";. Let's 3rd uri segment flexible not the 2nd. public function cucuru ($third_uri) {} RE: How to create routes using the MySQL database - mauro269 - 03-28-2016 Dear arma7x, thanks for your reply but this isn't what I'm looking for. If I use your $route, there will be no filter...instead, the cucuru should be limited only to some specific words (hundreds, but not infinite). A check of a specific table in the MySQL Database can filter the possible words that I can use in my URLs redirecting to "cucuru" method. RE: How to create routes using the MySQL database - arma7x - 03-28-2016 If searching in specific table does not found anything then show_404(). Or do switchcase/ifelse. Can you more specific on your question? RE: How to create routes using the MySQL database - mauro269 - 03-29-2016 Excuse me, I didn't understand. What I'm saying is that I don't want to use the (:any) but select the methods from my MySQL database or anything else that I can access. I hope now my request is more clear. RE: How to create routes using the MySQL database - PaulD - 03-29-2016 I think arma7x is correct btw. Why not use the :any command? Code: $route['rigatos/(:any)'] = "rigatos/cucuru/$1";. Now your rigatos controller checks to see if the collected variable is in your database. Code: class Rigatos extends CI_Controller { You said Quote:What I want to do is to have the same content of the "cucuru" method also for other methods, without the need to write other methods. That is a little confusing, but perhaps the curcuru function needs to be in a library, so other functions can call it at will? Perhaps if you give a little more information about what you are trying to achieve someone can suggest a better way to achieve it. Best wishes, Paul. RE: How to create routes using the MySQL database - mauro269 - 03-30-2016 Hello guys, I apologize for the late reply. So, you are saying that I should do the check directly inside the method(). Can I ask you to please help me on defining the instruction to check if $word is in the database? Thanks |