在单独的页面上显示搜索结果


Displaying search results on a separate page

我有一个SilverStripe网站与一些代码来显示搜索表单。for允许你搜索基于3个东西的东西。问题是,我不确定如何让结果正确显示在一个单独的页面上。

我代码:

class InstitutionSearchPage extends Page {  
}
class InstitutionSearchPage_Controller extends Page_Controller {
    private static $allowed_actions = array(
        'Search'
    );
    public function Form() {
        $fields = new FieldList(array(
            DropdownField::create('DegreeType', 'Degree', QualificationType::get()->filter('ParentID', 0)->map()),
            DropdownField::create('Course', 'Course', Qualification::get()->map()),
            DropdownField::create('City', 'City', City::get()->map()),
        ));
        $actions = new FieldList(array(
            FormAction::create('Search')->setTitle('Find a College')
        ));
        $validator = ZenValidator::create();
        $validator->addRequiredFields(array(
            'DegreeType' => 'Please select a Degree',
            'Course' => 'Please select a course',
            'City' => 'Please select a city',
        ));
        $form = new Form($this, 'Search', $fields, $actions, $validator);
        $form->setLegend('Criteria')->addExtraClass('form-horizontal')->setAttribute('data-toggle', 'validator');
        // Load the form with previously sent data
        $form->loadDataFrom($this->request->postVars());
        return $form;
    }
    public function Search() {
        return array('Content' => print_r($this->getRequest()->postVars(), true));
    }
}

它似乎在同一页面上显示结果,但给了我一堆奇怪的数据。例如,当我测试表单时,我得到了这个:Array ( [DegreeType] => 53 [Course] => 1 [City] => 1 [SecurityID] => 02718d0283e27eeb539eff19616e0b23eadd6b94 [action_Search] => Find a College )

结果应该是一个有组织的大学列表(以及其他数据)。

我猜你所看到的是预期的行为,因为表单将发布到搜索函数,并且一个只是返回一个数组的print_r,其中包含将由模板拾取的post变量。

否则,有很多事情与Silverstripe处理表单的默认方式不对应。请查看此处并相应地更改您的表单:https://docs.silverstripe.org/en/3.4/tutorials/forms/

例如,给表单赋予与函数相同的名称(或者在您的情况下,将函数名称更改为表单名称)。然后实现动作函数