21303 Posts in 5736 Topics by 2603 members
| Go to End | Next > | |
| Author | Topic: | 469 Views |
-
Search function on top

18 October 2011 at 12:21pm
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 ? ? -
Re: Search function on top

18 October 2011 at 9:45pm
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_searchi'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 ?
-
Re: Search function on top

24 October 2011 at 10:46am
<?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 addedcode 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? -
Re: Search function on top

24 October 2011 at 11:04am Last edited: 24 October 2011 11:04am
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
-
Re: Search function on top

24 October 2011 at 11:08am Last edited: 24 October 2011 11:10am
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 -
Re: Search function on top

24 October 2011 at 11:34am
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 "{$Title}"">Read more about "{$Title}"...</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> -
Re: Search function on top

25 October 2011 at 9:58am
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)
| 469 Views | ||
| Go to Top | Next > |



