• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create routes using the MySQL database

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.

$route['rigatos/(:any)'] = "rigatos/cucuru/$1";. Let's 3rd uri segment flexible not the 2nd. public function cucuru ($third_uri) {}
Keep calm.

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.

If searching in specific table does not found anything then show_404(). Or do switchcase/ifelse. Can you more specific on your question?
Keep calm.

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. Smile

I think arma7x is correct btw.

Why not use the :any command?

$route['rigatos/(:any)'] = "rigatos/cucuru/$1";.

Now your rigatos controller checks to see if the collected variable is in your database.

class Rigatos extends CI_Controller {

  public function cucuru($word='')
      // check to see if $word is in the database (or file, or array of acceptable terms, or whatever)

     // it is, great, do something

     // it is not, then deal with that


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,


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?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.