如何解决Silverstripe-常规搜索表单在“安全性/登录”页面上不起作用
|| 我已经在Page.php文件中定义了searchform 函数AdvancedSearchForm(){ $ searchText = isset($ this-> Query)吗? $ this-> Query:\'搜索\'; $ searchText2 = isset($ this-> Subquery)? $ this-> Subquery:\'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;
}
并且我的所有页面都从“页面”扩展而来,并且搜索表单位于标题中,因此出现在所有页面上。但是,当用户在“安全性/登录”页面上并尝试搜索某些内容时,他会收到以下错误消息
The action \'AdvancedSearchForm\' does not exist in class Security
我认为这是因为“安全”页面未从“页面”扩展而来。如何设置搜索依据,使其可以在包括系统页面(如安全性登录页面)在内的任何页面上使用?
解决方法
因为表格未传递到所需的控制器(〜Page_Controller),所以出现错误。
定义Form对象时,应测试$ this-> owner并查看它是否为Page_Controller的后代。如果没有,则可以使用类似的方法,并将$ controller用作Form对象创建中的第一个变量。
$sitetree_object = SiteTree::get_by_link(\'some-page-url\');
$controller = ModelAsController::controller_for($sitetree_object);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。