Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

[solved]enable_nested_urls affects global form in the page_controller, director rule issue


Reply


2 Posts   951 Views

Avatar
Ben_W

Community Member, 80 Posts

18 March 2011 at 8:53pm

Edited: 18/03/2011 8:55pm

I have created a form in the page_controller, so that it can be included in any other page which may require it. the code are as follow:

/**
    * Site search form
    */
   function DirectorySearchForm() {
      $theme_dir = $this->ThemeDir();
      
      $default_category = (isset($_GET['Category']))?$_GET['Category']:'';
$default_business_name = (isset($_GET['BusinessName']))?$_GET['BusinessName']:'';
      
      $mycat = array();
      
      $this->build_category_tree($mycat);
      
      $searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : '';
      $fields = new FieldSet(
         new LiteralField ("cate_span", '<span class="choose-category">Choose a business category</span>'),
         new SearchFormDropDownField(
             'Category',
             '',
             $mycat,
            $default_category,
            '',
            'Any Category'
         ),
         new LiteralField ("business_span", '<span class="business-name">Business name</span>'),
       new TextField("BusinessName", "", $default_business_name)
       );
      
      $myFormAction = new FormAction('searchResultProcess', 'SEARCH');
      $myFormAction->addExtraClass('submitBtn');
      
      $actions = new FieldSet($myFormAction);
            
      $mySearcgForm = new SearchForm($this, "DirectorySearchForm", $fields, $actions);
      $mySearcgForm->addExtraClass('search_form');
      
       return $mySearcgForm;
   }
   
   /**
    * Process and render search results
    */
   function searchResultProcess($data, $form){
       
      $page = DataObject::get('SearchResultPage', "", 'Sort', '', 1);
      $result_page = $page->First();
      $link = $result_page->Link();
      
      
      Director::redirect($link.'?BusinessName='.urlencode($data['BusinessName']).'&Category='.urlencode($data['Category']));      
   }

the process actually pass on the param to search result page, which will then be processed.
The problem that I am facing is that, this technique works in early versions. But with 2.4.5, after I turned on the 'enable_nested_urls'. This settings change the director behavior I guess. Now only level one directory will finds the DirectorySearchForm, any directory deeper than this will result in 404. take the following two page as example.

http://www.mydomain.com/business-directory/
this will work as expected.

http://www.mydomain.com/business-directory/professional-services/
form on this page does not work, will result in 404 page.

I have a feeling that it might have something to do with the 'Director' rules set up by the nested url. I have two level directory sitting under the 'business-directory'. Does anyone know how to solve this problem, not sure how to go about setting up the redirect rules for this. Please help. Cheers.

Avatar
Ben_W

Community Member, 80 Posts

20 March 2011 at 8:19pm

After some diagnoses, my finding is that it has nothing to do with enable_nested_urls, nor director:addRules.
I got the following code in my CategoryPage controller, which limits the allowed action. Totally forgot about his, so all I did was add the form action into this allowed action setting, and now the search form can be accessed from any page.

Sorry about the confusion.