Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/131809-regex-array-and-sql-queries/
Share on other sites

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.