當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SearchForm::setFormMethod方法代碼示例

本文整理匯總了PHP中SearchForm::setFormMethod方法的典型用法代碼示例。如果您正苦於以下問題:PHP SearchForm::setFormMethod方法的具體用法?PHP SearchForm::setFormMethod怎麽用?PHP SearchForm::setFormMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SearchForm的用法示例。


在下文中一共展示了SearchForm::setFormMethod方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getForm

 public function getForm($filters = true)
 {
     // Don't allow searching without a valid search engine.
     $engine = $this->data()->SearchEngine;
     $fulltext = Config::inst()->get('FulltextSearchable', 'searchable_classes');
     if (is_null($engine) || $engine === 'Full-Text' && (!is_array($fulltext) || count($fulltext) === 0)) {
         return $this->httpError(404);
     }
     // Construct the search form.
     $fields = new FieldList(TextField::create('Search', _t('SearchForm.SEARCH', 'Search'), isset($_GET['Search']) ? $_GET['Search'] : '')->addExtraClass('extensible-search search')->setAttribute('data-suggestions-enabled', Config::inst()->get('ExtensibleSearchSuggestion', 'enable_suggestions') ? 'true' : 'false')->setAttribute('data-extensible-search-page', $this->data()->ID));
     // When filters have been enabled, display these in the form.
     if ($filters) {
         $objFields = $this->data()->getSelectableFields();
         // Remove content and groups from being sortable (as they are not relevant).
         unset($objFields['Content']);
         unset($objFields['Groups']);
         // Remove any custom field types and display the sortable options nicely to the user.
         foreach ($objFields as &$field) {
             if ($customType = strpos($field, ':')) {
                 $field = substr($field, 0, $customType);
             }
             // Add spaces between words, other characters and numbers.
             $field = ltrim(preg_replace(array('/([A-Z][a-z]+)/', '/([A-Z]{2,})/', '/([_.0-9]+)/'), ' $0', $field));
         }
         $sortBy = isset($_GET['SortBy']) ? $_GET['SortBy'] : $this->data()->SortBy;
         $sortDir = isset($_GET['SortDir']) ? $_GET['SortDir'] : $this->data()->SortDir;
         $fields->push(new DropdownField('SortBy', _t('ExtensibleSearchPage.SORT_BY', 'Sort By'), $objFields, $sortBy));
         $fields->push(new DropdownField('SortDir', _t('ExtensibleSearchPage.SORT_DIR', 'Sort Direction'), $this->data()->dbObject('SortDir')->enumValues(), $sortDir));
     }
     $actions = new FieldList(new FormAction('getSearchResults', _t('SearchForm.GO', 'Search')));
     $form = new SearchForm($this, 'getForm', $fields, $actions);
     $searchable = Config::inst()->get('FulltextSearchable', 'searchable_classes');
     if (is_array($searchable) && count($searchable) > 0) {
         $form->classesToSearch($searchable);
     }
     $form->addExtraClass('searchPageForm');
     $form->setFormMethod('GET');
     $form->disableSecurityToken();
     return $form;
 }
開發者ID:helpfulrobot,項目名稱:nglasl-silverstripe-extensible-search,代碼行數:40,代碼來源:ExtensibleSearchPage.php


注:本文中的SearchForm::setFormMethod方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。