Jump to:

23000 Posts in 11854 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Search function on top

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

Page: 1 2
Go to End
Author Topic: 716 Views
  • alienn
    Avatar
    Community Member
    15 Posts

    Search function on top Link to this post

    Hey there
    I want to create search function on url mysite.com/search - 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 ? ?

  • SheaDawson
    Avatar
    Community Member
    45 Posts

    Re: Search function on top Link to this post

    Hey, maybe you could post your code?

  • alienn
    Avatar
    Community Member
    15 Posts

    Re: Search function on top Link to this post

    it's just copypasted code from tutorial here: http://doc.silverstripe.org/sapphire/en/tutorials/4-site-search 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 ?

  • alienn
    Avatar
    Community Member
    15 Posts

    Re: Search function on top Link to this post

    <?php
    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?

  • Webdoc
    Avatar
    Community Member
    329 Posts

    Re: Search function on top Link to this post

    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

  • alienn
    Avatar
    Community Member
    15 Posts

    Re: Search function on top Link to this post

    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

  • Webdoc
    Avatar
    Community Member
    329 Posts

    Re: Search function on top Link to this post

    Page_results.ss under yourtheme/layout/ must contains something like that:

    <div class="typography">
       <% if Results %>
        <ul id="SearchResults">
        <% control Results %>
        <li>
        <% 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 %>
           $Content.FirstParagraph(html)
              <% end_if %>
        <a class="readMoreLink" href="$Link" title="Read more about &quot;{$Title}&quot;">Read more about &quot;{$Title}&quot;...</a>
        </li>
        <% end_control %>
        </ul>
        <% else %>
        <p>
                <%-- Example of a translatable string (see http://doc.silverstripe.org/i18n) --%>
                <% _t("Page_results.ss.NORESULTS", "Sorry, your search query did not return any results.") %>
                <%-- By the way, template comments marked like this will be excluded from the HTML output --%>
             </p>
        <% 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 %>
        <span>
        <% control Results.SummaryPagination(5) %>
        <% if CurrentBool %>
        $PageNum
        <% else %>
        <a href="$Link" title="View page number $PageNum">$PageNum</a>
        <% end_if %>
        <% end_control %>
        </span>

        </div>
        <% end_if %>
    </div>

  • alienn
    Avatar
    Community Member
    15 Posts

    Re: Search function on top Link to this post

    i've copied Page_results.ss 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)

    716 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.