开发者

Silverstripe - Generic search form doesn't work on Security/Login page

开发者 https://www.devze.com 2023-03-09 01:57 出处:网络
I have defined a searchform in the Page.php file function AdvancedSearchForm() { $searchText = isset($this->Query) ? $this->Query : \'Search\';

I have defined a searchform in the Page.php file

function AdvancedSearchForm() { $searchText = isset($this->Query) ? $this->Query : 'Search'; $searchText2 = isset($this->Subquery) ? $this->Subquery : '0'; $searchText3 = isset($this->documentType) ? $this->documentType : 'All';

$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;

}

and all my pages are extended from Page and search form is in the header so appears on all pages. But when user is on Security/Login page and tries to search for something, he gets the following error message

The action 'AdvancedSearchForm' does not exist in class Security

I assume the reason for this is Securit开发者_如何学Pythony page is not extended from Page. How can I set the search from so that it will work on any page including system pages such as Security login page?


You are getting an error because the form is not being passed to the controller you want (~Page_Controller).

When you define the Form object, you should test $this->owner and see if it's a descendant of Page_Controller. If not, you could use something like this and use $controller as the first variable in your Form object creation.

$sitetree_object = SiteTree::get_by_link('some-page-url');
$controller = ModelAsController::controller_for($sitetree_object);
0

精彩评论

暂无评论...
验证码 换一张
取 消