Search on blog:

Kohana w przykładach: domyślny routing z argumentami dla strony

Przekazywanie argumentów do wywoływanej strony

bootstrap:

Route::set( 
    'default-z-argumentami', 
    '(/)((/(/(/(/(/(/(/))))))))', 
    array(
    // argumenty odzielone znakiem '/' (czyli ciągi znaków bez '/')
        'arg1' => '[^/]*', 
        'arg2' => '[^/]*',
        'arg3' => '[^/]*',
        'arg4' => '[^/]*',
        'arg5' => '[^/]*',
    // reszta (czyli wszystkie znaki w tym także '/')
    'rest' => '.*' 
    )
)
->defaults(
    array(
        'controller' => 'welcome',
        'action'     => 'index',
    )
);

controller:

public function action_index() 
{ 
    // pobierania argumentow 
    // jesli argument nie byl podany to param() domyslnie zwroci NULL
    $my_arg1 = $this->request->param('arg1'); 
    $my_arg2 = $this->request->param('arg2'); 
    $my_arg3 = $this->request->param('arg3'); 
    $my_arg4 = $this->request->param('arg4'); 
    $my_arg5 = $this->request->param('arg5'); 
    $my_rest = $this->request->param('rest');

    // wypisanie argumentow 
    // poniewaz wartosci NULL niewypisze wiec zamieniamy na odpowiedni tekst
    echo 'arg1: ', ( $my_arg1 === NULL ? 'NULL' : $my_arg1 ), '', PHP_EOL;
    echo 'arg2: ', ( $my_arg2 === NULL ? 'NULL' : $my_arg2 ), '', PHP_EOL;
    echo 'arg3: ', ( $my_arg3 === NULL ? 'NULL' : $my_arg3 ), '', PHP_EOL;
    echo 'arg4: ', ( $my_arg4 === NULL ? 'NULL' : $my_arg4 ), '', PHP_EOL;
    echo 'arg5: ', ( $my_arg5 === NULL ? 'NULL' : $my_arg5 ), '', PHP_EOL;
    echo 'rest: ', ( $my_rest === NULL ? 'NULL' : $my_rest ), '', PHP_EOL;
}
If you like it
Buy a Coffee