Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Search function on top

Go to End

9 Posts   906 Views


18 October 2011 at 12:21pm Community Member, 15 Posts

Hey there
I want to create search function on url - no search form on top of the page, just single subpage with search form and results
i've used the tutorial but it's not working (completly, got 404) - how to force the controller to display content from "search" method in the Page class insteed of 404 ? ?


18 October 2011 at 7:56pm Community Member, 46 Posts

Hey, maybe you could post your code?


18 October 2011 at 9:45pm Community Member, 15 Posts

it's just copypasted code from tutorial here: for "2.4 and newer"
with a differences:
- no $SearchForm on top of the page, just link to /search
- renamed function results to function search and Page_results to Page_search

i'll post exact code when i'll be back on my work computer, but like ive said its just copypasted

what possibly i've missed ?


24 October 2011 at 10:46am Community Member, 15 Posts

class SearchPage extends SiteTree {


class SearchPage_Controller extends Page_Controller {
   public function index() {
      return $this->render();
   public function results($data, $form) {
      $data = array(
         'Results' => $form->getResults(),
         'Query' => $form->getSearchQuery(),
         'Title' => 'Search Results'
      $this->Query = $form->getSearchQuery();
      return $this->customise($data)->renderWith(array('SearchPage_results','SearchPage'));

this is what i've done so far and still completly not working.
on index i just display template with $SearchForm added

code aboce generates form like:

<form id="SearchForm_SearchForm" action="/SearchPage_Controller/SearchForm" method="get" enctype="application/x-www-form-urlencoded">

how to change $searchForm ? need to change action value, and the submit button?


24 October 2011 at 11:04am (Last edited: 24 October 2011 11:04am), Community Member, 332 Posts

what version on ss are u using if 2.4.5 add in your mysite/_config.php this line - FulltextSearchable::enable(); - this line enables the search form


24 October 2011 at 11:08am (Last edited: 24 October 2011 11:10am), Community Member, 15 Posts

im using 2.4.5.
this line is added, rebuilded etc. i've followed the tutorial, but it didn't helped as only the (poorly working) search form is displayed, nothing else


24 October 2011 at 11:34am Community Member, 332 Posts under yourtheme/layout/ must contains something like that:

<div class="typography">
   <% if Results %>
    <ul id="SearchResults">
    <% control Results %>
    <% if MenuTitle %>
    <h3><a class="searchResultHeader" href="$Link">$MenuTitle</a></h3>
    <% else %>
    <h3><a class="searchResultHeader" href="$Link">$Title</a></h3>
    <% end_if %>
          <% if Content %>
          <% end_if %>
    <a class="readMoreLink" href="$Link" title="Read more about &quot;{$Title}&quot;">Read more about &quot;{$Title}&quot;...</a>
    <% end_control %>
    <% else %>
            <%-- Example of a translatable string (see --%>
            <% _t("", "Sorry, your search query did not return any results.") %>
            <%-- By the way, template comments marked like this will be excluded from the HTML output --%>
    <% end_if %>

    <% if Results.MoreThanOnePage %>
    <div id="PageNumbers">
    <% if Results.NotLastPage %>
    <a class="next" href="$Results.NextLink" title="View the next page">Next</a>
    <% end_if %>
    <% if Results.NotFirstPage %>
    <a class="prev" href="$Results.PrevLink" title="View the previous page">Prev</a>
    <% end_if %>
    <% control Results.SummaryPagination(5) %>
    <% if CurrentBool %>
    <% else %>
    <a href="$Link" title="View page number $PageNum">$PageNum</a>
    <% end_if %>
    <% end_control %>

    <% end_if %>


25 October 2011 at 9:58am Community Member, 15 Posts

i've copied from tutorial, but it's dont even accessed - i'm redirected to /SearchPage_Controller/SearchForm.
from the tutorial only input and submit button are working somehow (by working i meant that they are displayed, nothing more)

Go to Top