2011-05-27 81 views
0

上不工作我已經定義在page.php文件一個文件searchformSilverstripe - 通用搜索表單安全性/登錄頁

功能AdvancedSearchForm(){$ = SEARCHTEXT isset($這個 - >查詢)? $ 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; 

}

和我所有的網頁都從頁擴展和搜索的形式是在標題中,會出現在所有頁面上。但是,當用戶在安全/登錄頁面上,並試圖尋找的東西,他得到了以下錯誤消息

The action 'AdvancedSearchForm' does not exist in class Security 

我想這樣做的原因是安全網頁無法從頁擴展。我如何設置搜索以便它可以在任何頁面上工作,包括系統頁面,例如安全登錄頁面?

回答

2

您正在收到錯誤,因爲表單沒有傳遞給您想要的控制器(〜Page_Controller)。

當您定義表單對象時,您應該測試$ this-> owner並查看它是否是Page_Controller的後代。如果沒有,你可以使用這樣的東西,並使用$控制器作爲Form對象創建中的第一個變量。

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

這樣做的伎倆!非常感謝你。 – Optimus 2011-05-31 14:57:39

+0

雖然 – Optimus 2011-05-31 14:58:02

+0

糟糕,我必須將'ModelController'更改爲'ModelAsController'糟糕...是的,你是對的!很高興工作! – blu42media 2011-05-31 16:38:48