0

Page.phpファイルで検索フォームを定義しました

function AdvancedSearchForm(){$ searchText = isset($ this-> Query)?$ this->クエリ:'検索'; $ 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

これは、セキュリティページがページから拡張されていないためだと思います。セキュリティログインページなどのシステムページを含むすべてのページで機能するように、から検索を設定するにはどうすればよいですか?

4

1 に答える 1

2

フォームが目的のコントローラー(〜Page_Controller)に渡されていないため、エラーが発生します。

Formオブジェクトを定義するときは、$ this-> ownerをテストして、それがPage_Controllerの子孫であるかどうかを確認する必要があります。そうでない場合は、このようなものを使用して、フォームオブジェクト作成の最初の変数として$controllerを使用できます。

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