ibinod Posted November 7, 2008 Share Posted November 7, 2008 Hi, i am creating db based routes for my sef urls and i am in need of some help here currently without using database this is my routes struction $routes = array ( array('url' => '/^cats\/?$/', 'controller' => 'cats', 'view' => 'show'), /*[... and so on]; */ ); but i am trying to replace the value cats from the value in my database like.. $row['link']; i tried to use foreach and while loopes after array ( //foreach loops ); but i get an error, can someone pls guide the right way to do this or some alternative way to store my routes for my simple mvc framework in database. Quote Link to comment https://forums.phpfreaks.com/topic/131809-regex-array-and-sql-queries/ Share on other sites More sharing options...
sasa Posted November 7, 2008 Share Posted November 7, 2008 try <?php foreach ($routes as $key => $val){ foreach ($val as $key2 => $val2){ $routes_new[$key][$key2] = str_replace('cats', $row['link'], $val2); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/131809-regex-array-and-sql-queries/#findComment-684719 Share on other sites More sharing options...
ibinod Posted November 7, 2008 Author Share Posted November 7, 2008 hi, sasa thank you very much for your prompt reply i tried but i don't think it worked as i wanted pls let me explain this a bit my database has menu table which contains various columns which have one link column and my index file routes like this define('APP_DIR','mvc'); $url = $_SERVER['REQUEST_URI']; $url = preg_replace('/^\/('.APP_ROOT.'\/)?/','',$url); $params = array(); //this holds various variables values passed $match_route = false; //makes the route match false by default //routes to loop for the given url $routes = array ( array('url' => '/^$/', 'controller' => 'home', 'view' => 'home'), // this routes to the home page or default page array('url' => '/^cats\/?$/', 'controller' => 'category', 'view' => 'home'), // this routes to the categories page array('url' => '/^cats\/(?P<view>\d+)\/([0-9A-Za-z_-]+)\/?$/', 'controller' => 'viewcat', 'view' => 'viewcat_home') // this routes to the view cats page ); foreach ($routes as $urls => $route) //loops over the urls to route { if (preg_match($route['url'], $url, $matches)) { $params = array_merge($params, $matches); //mergest the url value with params array $match_route = true; // makes the route match true break; //breaks the loop once route is found } if(!$match_route) { die('The are no such routes'); // gives error if no matches are found } include(CONTROLLER_PATH.$route['controller'].'php'); // inlcludes the required controller include(TEMP_PATH.'skins/template.php'); //includes the default template } so all i want to is store the routes on my database so pls give me some suggestion on this Quote Link to comment https://forums.phpfreaks.com/topic/131809-regex-array-and-sql-queries/#findComment-684729 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.