Just for your referece, below is how I do the trick.
1, you should have a page contains search form, somethiing like:
<ul class="nav navbar-nav navbar-right">
<li>
<form id="search-form" class="navbar-form navbar-left" role="search">
<div class="form-group">
<?php $search = isset($search) ?$search: null?>
{{ text_field("search",'class':'form-control','placeholder':'Search','value':search) }}
</div>
<button type="submit" class="btn btn-default">查询</button>
</form>
</li>
</ul>
2, using some js to get the post request to get request.
$(function() {
$("#search-form").submit(function() {
var keywords;
keywords = $("#search").val().trim();
keywords = keywords.replace(/\//, ' ');
location.href = "https://" + location.host + ("/search/" + keywords);
return false;
});
3,In order to get this url working, you should define some route like :
$router->add('/search/{search:[^/]+}','standards::search')->setName('standards.search');
$router->add('/search/{search:[^/]+}/page/{page:[0-9]+}','standards::search')->setName('standards.search.page');
4,And the controller should be something like :
public function searchAction($search,$page = 1)
{
if(myToolsFacade::isStandardNumber($search)) {
$file = Files::findByStandardNumber($search);
if($file) return $this->redirectByRoute(['for'=>'standards.show','file'=>$file->id]);
}
$this->view->page = $this->getPaginatorByQueryBuilder(Files::searchQuery($search),50,$page);
$this->view->search = $search;
}
5,In the (search.volt) view file, you could use the $page variable to set the navigate link, like :
{% block nav %}
<div><span class="label label-primary">共计{{ page.total_items }}条标准</span>--<span class="label label-primary">第{{ page.current }}页/总{{ page.total_pages }}页</span></div>
{% if page.total_items > page.limit %}
<nav>
<ul class="pager">
<li class="previous"><a href="{{ url(['for':'standards.search.page','search':search,'page':page.before]) }}"><span aria-hidden="true">←</span> 上一页</a></li>
<li class="next"><a href="{{ url(['for':'standards.search.page','search':search,'page':page.next]) }}">下一页 <span aria-hidden="true">→</span></a></li>
</ul>
</nav>
{% endif %}
{% endblock %}