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 ? ?
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
- Page 11(current)
- 2
- Next 10 entries
Hey, maybe you could post your code?
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 ?
<?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?
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
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
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>
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)
- Page 11(current)
- 2
- Next 10 entries