Welcome Guest, Not a member yet? Register   Sign In
Dynamic routing names
#5

Cheers for the link, I wouldn't worry too much about caching the routes, one extra DB query isn't going to make much difference for most apps.

Having a dedicated routes table would defo be an option.

Sometimes I would add extra routes like so, just a quick dirty method that limits the number of queries needed to one.

PHP Code:
if($uri[1]) //Not the homepage then check slugs
{
    if(
$uri[1] == 'blog' && $uri[2] == 'category' && $uri[3])
    {
        
//Check blog category slugs
        
$db->select('cat_id, cat_slug');
        
$db->where('cat_slug'$uri[3]);
        
        if(
$category $db->get('tbl_blog_category')->row_array())
        {
            
$route['blog/category/'.$category['cat_slug']] = 'blog/category/'.$category['cat_id'];
        }
    }
    elseif(
$uri[1] == 'blog' && $uri[2])
    {
        
//Check blog category slugs
        
$db->select('post_id, post_slug');
        
$db->where('post_slug'$uri[2]);
        
$db->where('post_live'1);
        
        if(
$post $db->get('tbl_blog_post')->row_array())
        {
            
$route['blog/'.$post['post_slug']] = 'blog/post/'.$post['post_id'];
        }
    }
    else
    {
        
//Some first level route
        
$db->select('sho_id, sho_slug');
        
$db->where('sho_slug'$uri[1]);
        
$db->where('sho_live'1);
        
        if(
$show $db->get('tbl_show')->row_array())
        {
            
$route[$show['sho_slug']] = 'shows/view/'.$show['sho_id'];
        }
    }

Reply


Messages In This Thread
Dynamic routing names - by ignitedcms - 10-21-2015, 03:14 PM
RE: Dynamic routing names - by AidanW - 10-21-2015, 03:28 PM
RE: Dynamic routing names - by PaulD - 10-21-2015, 05:56 PM
RE: Dynamic routing names - by ignitedcms - 10-21-2015, 11:12 PM
RE: Dynamic routing names - by AidanW - 10-22-2015, 12:06 AM
RE: Dynamic routing names - by John_Betong - 10-22-2015, 02:13 AM
RE: Dynamic routing names - by ignitedcms - 10-23-2015, 10:57 AM
RE: Dynamic routing names - by puneetkumar - 07-13-2018, 12:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB