Welcome Guest, Not a member yet? Register   Sign In
How to call controllers from a database?
#2

[eluser]Bart v B[/eluser]
I think I've found a solution.
Really dirty, but it works fine :coolsmirk:

Just make a hook..

Code:
<?php

class RouterHook
{
    function GetRoutes()
    {

       //connect to the database in my case is that also dynamic ;)
       $db_conn = mysql_connect(DB_HOST, DB_USER, DB_PW);
       mysql_select_db(DBASE,$db_conn);
    
       // whipe out the '/' from the request_uri
       $uri = str_replace('/', '', $_SERVER['REQUEST_URI'] );
        
       $sql = "SELECT controller
               FROM
               routes
               WHERE
               controller = '".mysql_real_escape_string($uri)."'";
        
       $result = mysql_query($sql);
       // count the rows
       $numRows = mysql_num_rows($result);
       // if the controller does not exists..    
       if($numRows == 0)
       {
         //but when it's not the default controller
         if($_SERVER['REQUEST_URI'] != '/')
         {
           // were going to give it an error..
           $this->error();                
         }
            
       }    
        mysql_close($db_conn);    
    }
    
  function error()
  {
    //Tada ;)
    header('Location:/error/');
    exit();
  }
}


Messages In This Thread
How to call controllers from a database? - by El Forum - 08-21-2010, 11:57 AM
How to call controllers from a database? - by El Forum - 08-22-2010, 08:14 AM
How to call controllers from a database? - by El Forum - 08-22-2010, 08:52 AM
How to call controllers from a database? - by El Forum - 08-22-2010, 09:40 AM
How to call controllers from a database? - by El Forum - 08-22-2010, 07:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB