Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Application Sub-Routing

Let's say we have an app called awesomeness.
Right now I have site.com/awesomeness/{action} which works 100%.
Now awesomeness has an admin section as well, so I'm currently using site.com/awesomenessadmin/{action} which I'm not very happy about.

What sort of action would I need to take to use subrouting, ie make /admin/ point to a controller and not a method. I tried making a controller called AdminController, and inheriting from my AwesomenessController. It didn't seem to work, and the other issue is the admin stuff needs to inherit from DashboardController from what I understand, and php doesn't support multiple inheritance if I recall.

Obviously I need support for many subroutes, such as /admin/event/add etc

I was thinking perhaps I need to write two apps, one of the actual user interaction, and one for the admin backend.

Any advice would be appreciated :)

Tagged:

Comments

  • ToddTodd Chief Product Officer Vanilla Staff

    AdminController should work. It may be that you have to delete /cache/*.ini when you add it though.

    You don't need to inherit from DashboardController, but you'll need to add the methods to add side panels and whatnot. I can help you work through it in this thread, but let's get your admin controller working first. Make sure:

    1. You file is named class.admincontroller.php.
    2. AdminController inherits from AwesomenessController which inherits from Gdn_Controller.
  • Thanks so much Todd, that will be highly appreciated. I've done what you've mentioned. I've also made a Github repo for this to help anyone else experiencing difficulties, and to increase visibility (Maybe this can be integrated into the docs in future?)

    Here is the repo for anyone interested

    Currently in class.admincontroller.php:22, notice that calling the parent controller essentially removes the required admin Styles etc. This is why I wasn't inheriting from my base Awesomeness controller in the first place;but obviously it's required for the routing. Any ideas as to how can this be fixed eloquently ?

  • ToddTodd Chief Product Officer Vanilla Staff

    You need to do the stuff that the dashboard controller does to go into admin mode. Add the following to your AdminController.

    public function Initialize() {
          $this->Head = new HeadModule($this);
          $this->AddJsFile('jquery.js');
          $this->AddJsFile('jquery.livequery.js');
          $this->AddJsFile('jquery.form.js');
          $this->AddJsFile('jquery.popup.js');
          $this->AddJsFile('jquery.gardenhandleajaxform.js');
          $this->AddJsFile('global.js');
    
          $this->AddCssFile('admin.css');
    
          $this->MasterView = 'admin';
          parent::Initialize();
    }
    
    public function AddSideMenu($CurrentUrl = FALSE) {
        if(!$CurrentUrl)
            $CurrentUrl = strtolower($this->SelfUrl);
    
      // Only add to the assets if this is not a view-only request
      if ($this->_DeliveryType == DELIVERY_TYPE_ALL) {
         // Configure SideMenu module
         $SideMenu = new SideMenuModule($this);
         $SideMenu->HtmlId = '';
         $SideMenu->HighlightRoute($CurrentUrl);
            $SideMenu->Sort = C('Garden.DashboardMenu.Sort');
    
         // Hook for adding to menu
         $this->EventArguments['SideMenu'] = &$SideMenu;
         $this->FireEvent('GetAppSettingsMenuItems');
    
         // Add the module
         $this->AddModule($SideMenu, 'Panel');
      }
    }
    

    In methods within your controller make sure you cann $this->AddSideMenu() before calling render.

  • edited December 2011

    I actually had added that already, see this

    But my issue with calling the parent init still stands :P

  • ToddTodd Chief Product Officer Vanilla Staff

    Call parent::Initialize() first or not at all. Should be fine if you just add the code from Gdn_Controller->Initialize().

    public function Initialize() {
          if (in_array($this->SyndicationMethod, array(SYNDICATION_ATOM, SYNDICATION_RSS))) {
             $this->_Headers['Content-Type'] = 'text/xml; charset='.C('Garden.Charset', '');
          }
    
          if (is_object($this->Menu))
             $this->Menu->Sort = Gdn::Config('Garden.Menu.Sort');
       }
    
Sign In or Register to comment.