2

Just jumping into Resource Router by Rob Sanchez and hit a wall already. I've forgone the category URL indicator as I believe it works without it. I'm attempting to achieve the following URL structure:

/posts/ -Display a list of ALL categories

/posts/category_url -Display a list of entries belonging to the category

/posts/category_url/entry_url -Display an entry that has the category

I currently have:

$env_config['resource_router'] = array(
        'posts/:category/:any' => function($router, $wildcard_1, $wildcard_2) {
                // is segment_3 a valid URL title?
                if ($wildcard_2->isValidUrlTitle()) {
                    $router->setTemplate('templates/view');
                }   //is segment_2 a valid category URL title?
                elseif ($wildcard_1->isValidCategoryUrlTitle()) {
                    $router->setTemplate('templates/cat_entries');
                } 
                else { //We're at the root - show category list
                    $router->setTemplate('templates/cat_overview');
                }
         }
);

The Valid URL title portion works but stumped on what I require to get the other 2 working. Any insight gratefully accepted.

2 Answers 2

5

You can do this without a callback function:

$config['resource_router'] = array(
    'posts' => 'templates/index',
    'posts/:category_url_title' => 'templates/cat_entries',
    'posts/:category_url_title/:any' => 'templates/view',
);
0

The way I've done it before:

posts/:any           => templates/index,
posts/:any/:any      => templates/cat_entries,
posts/:any/:any/:any => templates/view
1
  • Marked Rob's as the answer as it had that little more error checking then a simple :any approach. Much appreciated the speed of your help however. Feb 8, 2015 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.