Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Problem with Routes.php
  • As a novice, I keep struggling with the Routes.php. I am building an app with several forms (ie. website, hardware, software, contact) and I want each form to have its own controller (same names, ie. website, hardware, software, contact).

    For some reasons the controller 'website' is prepended to every controller/action combination I refer to. This is my current Routes.php:

    <?php
    return array(
        '_root_'  => 'website/home',  // The default route
        
        'website/hardware(/:any)' => 'hardware/$1',
        'website/software(/:any)' => 'software/$1',
        'website/contact(/:any)' => 'contact/$1',   

    );

    What is the right way to do this?

  • What do you mean by "the controller 'website' is prepended to every controller/action combination I refer to"?
  • Example:

    <a href="website/hardware">

    The first time I click on this link, I'm routed to /website/hardware, which is OK.

    The second time I click on this link, I'm routed to /website/website/hardware, which is NOK

     

  • This is because you're using relative URI's in your HTML anchor.

    Ideally you should not hardcode anything in your views. Either use Html::anchor() to generate the anchor, or if you want to code HTML yourself, use:

    <a href="<?php echo Uri::create("website/hardware"); ?>">

    to make sure you're links are generated correctly.
  • Yep, this works. Thx.

     

Howdy, Stranger!

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

In this Discussion