Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8960183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:36:53+00:00 2026-06-15T15:36:53+00:00

I am trying to implement a search module with clean URLs. Something like www.website.com/search/

  • 0

I am trying to implement a search module with clean URLs. Something like http://www.website.com/search/searchterm. I have made a searchable index with EWZSearchBundle, so there is no database involved and therefore, no entity required.

public function searchAction(Request $request)
{
    $form = $this->createFormBuilder()
        ->add('query', 'text')
        ->getForm();

    if('POST' === $request->getMethod()){
        $form->bind($request);
        if ($form->isValid()) {
            return $this->redirect($this->generateUrl('search_process', array('query' => $request->query->get('query'))));
        }

    }

    return array(
        'form'   => $form->createView(),
    );
}

I created a simple form without an entity and sent the form action to itself. Where it reads a if it a POST request I validate the form and send it to search process with a clean URL (www.website.com/search/searchterm).

public function searchProcessAction($query)
{
    $search = $this->get('ewz_search.lucene');
    $results = $search->find($query);

    return array(
        'results'   => $results,
    );
}

In the search process I get the search term from the clean URL and search for it in my index and return the results. It should be a very simple process only one problem.

Since I don’t need to use an Entity, it never becomes a POST request and never gets inside the if('POST' === $request->getMethod()), and now that it becomes a GET request, it also spoils my whole thing about keeping the URL clean.

I know my way makes and extra redirect, but I don’t know how else to keep a clean URL for search. I’m open to any suggestions about the whole process.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:36:54+00:00Added an answer on June 15, 2026 at 3:36 pm

    I managed to get it working without using the form component. I made the form manually, also accepted the query string format suggested by @moonwave99. Using the form component gives longer names like form[query] and form[_token] where it sends that form’s CSRF token in the URL. Making the form manually allows better control on URL for query string format.

    Note: Beware that at the same time, it removes CSRF security from that particular form.

    Thanks for all the answers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a search on my website. Getting started, I have
I was trying to implement binary search tree but I think I have made
Hey folks I am trying to implement a search functionality in a website using
I am trying to implement an efficient algorithm for nearest-neighbour search problem. I have
Im trying to implement the search feature in my website. when the search keyword
I'm trying to implement a search, where you can enter more than one searchterm
I am trying to implement the binary search in python and have written it
I am trying to implement a search like the one used on the app
I am trying to implement Haystack search for my website with Whoosh back-end. I
I am trying to implement a search feature into my codeIgniter project. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.