Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Routing problems
  • Hi,
    I have problem with routing rules, I've tried all options mentioned in the docs, but i can't get it works...

    I have this configuration in my app/config/routes.php

    <?php<br />return array(
    '_root_' => 'welcome/index',
    '_404_' => 'welcome/404',

    'sat/(:categoria)/lista' => 'sat/index/$1', // categoria N1
    'sat/(:categoria)/(:subcategoria)/lista' => 'sat/index/$1/$2', // categoria N2
    'sat/(:categoria)/(:subcategoria)/(:subsubcategoria)/lista' => 'sat/index/$1/$2/$3', // categoria N3

    'sat/(:video)/video' => 'video/index/$1', // Detalle video sin cateogorias
    'sat/(:categoria)/(:video)/video' => 'video/index/$2/$1', // Detalle video en N1
    'sat/(:categoria)/(:subcategoria)/(:video)/video' => 'video/index/$3/$2/$1', // Detalle video en N2
    'sat/(:categoria)/(:subcategoria)/(:subsubcategoria)/(:video)/video' => 'video/index/$4/$3/$2/$1', // Detalle video en N2

    'descarga/(:any)' => 'descarga/index/$1',

    'login' => 'user/login',
    );


    This is my video controller:

    <?php<br />class Controller_Video extends Controller_Template {

    public function before() {
    parent::before();
    }

    public function action_index($video, $categoria = null, $subcategoria = null, $subsubcategoria = null) {


    echo 'Get all params:
    ';
    Debug::dump(Request::active()->params());
    echo '
    ';

    echo 'Get one by one param
    ';
    echo 'CATEGORIA = '.$categoria.'
    ';
    echo 'SUBCATEGORIA = '.$subcategoria.'
    ';
    echo 'SUBSUBCATEGORIA = '.$subsubcategoria.'
    ';
    echo 'VIDEO = '.$video.'
    ';

    die();

    }

    }


    The result is:
    ------------------------------------
    Get all params:
    APPPATH/classes/controller/video.php @ line: 13
    Variable #1:
    (Array, 1 element) ↵
    video (String): "my-category/my-video" (20 characters)



    Get one by one param
    CATEGORIA = my-video
    SUBCATEGORIA =
    SUBSUBCATEGORIA =
    VIDEO = my-category
    ------------------

    1 - Not detects the path separator
    2 - Not respects the order of the params

    I'm doing something wrong?

    Thanks ;-)
  • There are some modification generated in the wysiwyg area... sorry.
  • What is the exact URI you are trying?
  • In the example mentioned above I used this:
  • HarroHarro
    Accepted Answer
    Named parameters in routes are wildcard regexes.

    As they are processed top to bottom, the first one to match is used. So it's important that you put the most significant route first. I suggest you flip them around:
    'sat/(:categoria)/(:subcategoria)/(:subsubcategoria)/(:video)/video' => 'video/index/$4/$3/$2/$1', // Detalle video en N2        
    'sat/(:categoria)/(:subcategoria)/(:video)/video' => 'video/index/$3/$2/$1', // Detalle video en N2
    'sat/(:categoria)/(:video)/video' => 'video/index/$2/$1', // Detalle video en N1
    'sat/(:video)/video' => 'video/index/$1', // Detalle video sin cateogorias

  • Working! Thanks

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion