Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Routes sending parameters
  • Hello people,

    Does anyone know how I do with static routes parameters?
    I tried this way but does not work.

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

        'services' => array('institucional/index/&category=1', 'name' => 'services'),
        'company' => array('institucional/index/&category=2', 'name' => 'company'),
    );
  • What do you mean with "static routes parameters"?
  • Do you mean GET variables? Like "institucional/index?category=1"?

    Fuel doesn't work with GET variables, it works with URI segments for parameters, like "institucional/index/category/1" which can be routed without problems.
  • Did the way you told me, but how do I get the value of the thread?
    Thus returns under empty.

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

        'services' => array('institucional/index/category/1', 'name' => 'services'),
        'company' => array('institucional/index/category/2', 'name' => 'company'),
    );

    Controller:
       public function action_index()
        {
            $view = View::forge('institucional/index');
            $view->category = $this->param('category');
            $this->template->content = $view;
        }

    View:
    <h1><?php echo $category;?></h1>
  • As a parameter of the action method.

    If you provide a default:

    public function action_index($category = null)
    {
    }

    then the value is optional (i.e. "institucional/index/category" will work too), but of you don't

    public function action_index($category)
    {
    }

    then the parameter is required, and "institucional/index/category" will throw a HttpNotFoundException (a 404).
  • Problem solved!
    It worked perfectly.
    Thanks man.

Howdy, Stranger!

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

In this Discussion