Jump to:

22977 Posts in 11742 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » [solved]enable_nested_urls affects global form in the page_controller, director rule issue

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

Page: 1
Go to End
Author Topic: 889 Views
  • Ben_W
    Avatar
    Community Member
    79 Posts

    [solved]enable_nested_urls affects global form in the page_controller, director rule issue Link to this post

    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.

  • Ben_W
    Avatar
    Community Member
    79 Posts

    Re: [solved]enable_nested_urls affects global form in the page_controller, director rule issue Link to this post

    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.

    889 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.