Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Implementing Search. Problem with routes
  • Hello, folks I'm kinda stuck with Routes.

    there is a search-form in a top-navigation (twitter bootstrap)

    html here

    So if I make a request, the URL looks like

    fuelphp.dev/search/?q=qwerty

    wich is fine. With that URL the user should get results for his/her request provided by action_index()

    but if the user goes to fuelphp.dev/search/ (without any parameters), he/she should see the "advanced Search-form" provided by action_advanced()

    I alredy created a Controller_Search

    classes/controller/search.php (Controller)

    see code here

    and View

    views/search/index.twig (View)

    see code here

    the problem is - I don't know how to (re)write routes for that.

    if I add 'search' => 'search/advanced' to the routes.php it doesnt work correctly.

    Requestin fuelphp.dev/search/?q=qwerty triggers action_advanced() of Controller_Search too, whereas it should trigger action_index()

    How should I rewrite my routes (or maybe Controller logic) to get this working ?

  • HarroHarro
    Accepted Answer
    No need for routes.

    Just check in your method if the search criteria is present. If so, run the search and present the result. If not, display the search form.

    If you want two different methods for this, have the index() do a redirect if no criteria is present.
  • Ok, thanks! It works. I wonder if it possible to get the same behavior with routes?

Howdy, Stranger!

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

In this Discussion