我正在处理一个搜索表单,我想通过网址中的值发布搜索结果。我无法获取包含参数的网址。如果我在视图中键入值(如果不是$ this-> search_zip I键'12345'),它们将发布。目前,除了URL之外,搜索按预期工作。我目前从表单中获取搜索条件,我是否需要更改控制器设置以从网址获取它们?如果是这种情况我将如何过滤?
最终我想要我的网址阅读:
results / 12345 / otherparam
我目前正在
结果
无论我键入表单的变量是什么。
模块配置
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'segment',
'options' => array(
'route' => '/',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
'may_terminate' => true, //START OF CHILD ROUTES
'child_routes' => array(
'results' => array(
'type' => 'segment',
'options' => array(
'route' => 'results[/:search_zip][/:search_industry]',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'results',
结果视图
$form->setAttribute('action', $this->url(
'home/results',
array(
'action' => 'results',
'search_zip'=> $this->search_zip,
'search_industry' => 'industry_name'
echo $this->formRow($form->get('industry_name'));//this is the form field
echo $this->formSubmit($form->get('submit'));
控制器
//beginning of the results action
$request = $this->getRequest();
$form = new SearchForm($dbAdapter);
if ($request->isPost()) {
$search = new MainSearch();
$form->setInputFilter($search->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
在我的resultsAction结束时,我返回表单和结果(根据专辑示例)
return array(
'form' => $form,
'pros' => $fetchPros,
);
谢谢你, 中号
答案 0 :(得分:0)
//This will give you an array containing your desired parameters
$params = $this->params()->fromRoute();
//Then you can simply use them like this
$search_zip = $params['search_zip'];
$search_industry = $params['search_industry'];