3.1.3 - Router slug

New Feature : Router slug

Your component is now able to re-use the alias (From the alias Wizard) for creating beautiful URLs.
It works also for Foreign Key filters.
The following examples are available in the sample component (Hello My World)

Slug

Here an example with slug :
index.php/component/hellomyworld/city/city/9-canberra

or :
index.php/component/hellomyworld/city/city/canberra

Filters

Example with continent filter:
index.php/component/hellomyworld/cities/cities/europe

Example with country filter (in second position):
index.php/component/hellomyworld/cities/cities/-/france

Example with continent + country filter:
index.php/component/hellomyworld/cities/cities/europe/france

Configuration

To custom the router, simply refers to the bottom of the router.php file, in the XxxxRouteConfig()
The first index is always the view name.
Then, every sub entry represent the order of the segments.

array(

// CITY (ITEM)

    // First segment : VIEW name
    'city' => array(

        // Second segment : LAYOUT name
        array(
            'type' => 'layout'
        ),

        // Third segment : SLUG
        array(
            'type' => 'slug',
            'aliasKey' => 'alias'   // The router must know the alias field to search on
        )
    ),

// CITIES (LIST)

    // First segment : VIEW name
    'cities' => array(

        // Second segment : LAYOUT name
        array(
            'type' => 'layout'
        ),

        // Third segment : FILTER (continent)
        array(
            'type' => 'filter',
            'name' => 'country_continent',  // Filter name
            'model' => 'continent',         // Must know the name of the model to search on
            'aliasKey' => 'alias'           // If the related model has a slug, you can define this alias key (it will automatically instance a slug)
        ),

        // Fourth segment : FILTER (country)
        array(
            'type' => 'filter',             
            'name' => 'country',            // Filter name
            'model' => 'country',           // Must know the name of the model to search on
            'aliasKey' => 'alias'           // If the related model has a slug, you can define this alias key (it will automatically instance a slug)
        ),

        // Fifth segment : FILTER (travellers)
        array(
            'type' => 'filter',             
            'name' => 'travellers',         // Filter name
            // 'model' => 'traveller'       // Model is not required if there is no slug
        )
    ),

// TRAVELER

    // First segment : VIEW name
    'traveller' => array(

        // Second segment : LAYOUT name
        array(
            'type' => 'layout'
        ),

        // Third segment : Primary key (cid)
        array(
            'type' => 'var',    // In this case, the primary key is NOT handled by slug (no alias wizard for this table)
            'name' => 'cid'     // Will simply put an integer value in the segment
        )
    ),
);

This configuration is shared between parseRoute() and buildRoute()
You can try to change the order of the segments to see how your component manage easily the route.

I jumped and started to work on a demo component... but 2 days later this demo component became the real component. I just showed today the end result to my customer and he turned to me and said... "this is more than I expected"... All of this is because Cook did cut about 70% of my work and provided me more ways to improve the usability of the component. The end result was 17 tables all related between than to generate a full dashboard for the travel agents. Thanks for Cook developers for such great tool. This component would not be possible to be done at short time with all the features in it
Griiettner (Forum)  

Get Started