0

我在 Page.php 文件中定义了一个搜索表单

函数 AdvancedSearchForm() { $searchText = isset($this->Query) ?$this->Query : '搜索'; $searchText2 = isset($this->Subquery) ?$this->子查询:'0'; $searchText3 = isset($this->documentType) ?$this->documentType : '全部';

$searchSections = DataObject::get('SearchSection');
$ss = array();
foreach ($searchSections as $section) {
    $ss[$section->ID] = $section->Name;
}

$fileTypes = DataObject::get('FileType');
$ft = array();
foreach ($fileTypes as $type) {
    $ft[$type->ID] = $type->Name;
}
$ft[0] = 'All';
ksort($ft);

$fields = new FieldSet(
    new TextField('Query','Keywords', $searchText),
    new DropdownField('Subquery', '', $ss, $searchText2),
    new DropdownField('documentType', '', $ft, $searchText3)
);
$actions = new FieldSet(
    new FormAction('AdvancedSearchResults', 'Search')
);
$form = new Form($this->owner, 'AdvancedSearchForm', $fields, $actions);
$form->setFormMethod('GET');
$form->setTemplate('Includes/SearchForm');
$form->disableSecurityToken();

return $form;

}

并且我的所有页面都是从 Page 扩展而来的,并且搜索表单位于标题中,因此出现在所有页面上。但是当用户在安全/登录页面上并尝试搜索某些内容时,他会收到以下错误消息

The action 'AdvancedSearchForm' does not exist in class Security

我认为这是因为安全页面没有从页面扩展。如何设置搜索,以便它可以在任何页面上工作,包括系统页面,例如安全登录页面?

4

1 回答 1

2

你得到一个错误,因为表单没有被传递给你想要的控制器(~Page_Controller)。

定义 Form 对象时,应该测试 $this->owner 并查看它是否是 Page_Controller 的后代。如果没有,您可以使用类似的东西并使用 $controller 作为您的 Form 对象创建中的第一个变量。

$sitetree_object = SiteTree::get_by_link('some-page-url');
$controller = ModelAsController::controller_for($sitetree_object);
于 2011-05-31T14:25:16.427 回答