1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Creating Sub Pages within a Mod?

Discussion in 'XenForo Development Discussions' started by Jaxel, Oct 6, 2010.

  1. Jaxel

    Jaxel Well-Known Member

    Okay, previously I created a mod active at:
    http://xen1.8wayrun.com/portal/

    I would now like to make sub pages:
    http://xen1.8wayrun.com/portal/lorem
    http://xen1.8wayrun.com/portal/ipsum
    http://xen1.8wayrun.com/portal/dolor

    Basically, I will have a database table of subpages (this will be a lite CMS) where the name of the page will be the unique key (if a numeric node id is required, then thats okay too). So when someone goes to /portal/lorem, it will extract the word "lorem" and search the database for the matching result; then display it. Since there will be many pages, and all with different names, its not feasible to create an action for each and every page. So I want the actions created dynamically, the same way thread and member page actions are created.

    How would something like this be accomplished?
     
  2. Mythotical

    Mythotical Well-Known Member

    Within the Index.php file of your portal you will create a new function like so:
    PHP:
    public funtion actionLorem {
    // code goes here
    }
    Then you can access it via the address above using /lorem/
     
  3. Jaxel

    Jaxel Well-Known Member

    Steve... I already said in my original post that defined functions would not be feasible.

    If I release this mod to the public, administrators will be able to name their pages anything they want... and I don't expect them to what to have to define a function for each and every page.
     
  4. Mythotical

    Mythotical Well-Known Member

    You would have to do a foreach in the page to display but you would still need to use an action controller to view the page no matter what. So you would need to do something like: portal/page?lorem/

    That is the only feasible way I can think to go about it.
     
  5. Jaxel

    Jaxel Well-Known Member

  6. Mythotical

    Mythotical Well-Known Member

    Good point, open up: library/XenForo/ControllerPublic/User.php

    Look through there for the proper way to do just that.
     
    cedivad likes this.
  7. ragtek

    ragtek Guest

    I think you have to use a router for this.
     
  8. Jaxel

    Jaxel Well-Known Member

    You mean library/XenForo/ControllerPublic/Member.php

    And I've been looking through it, and I can't get anything working...

    My route prefix looks like this:
    Code:
    <?php
    
    class EWRporta_Route_Prefix_Portal implements XenForo_Route_Interface
    {
    	public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    	{
    		$action = $router->resolveActionWithStringParam($routePath, $request, 'pageName');
    		return $router->getRouteMatch('EWRporta_ControllerPublic_Portal', $action, 'EWRporta');
    	}
    }
    I figured it would be as simple as putting this at the beginning of my index to retrieve the data, but I cant get it working:
    Code:
    $pageName = $this->_input->filterSingle('pageName', XenForo_Input::STRING);
     
  9. ponology

    ponology Member

    I'm not sure if this is the best way but it worked:

    Go to AdminCP > Development > Route Prefixes. Add a new one for you (let's say "portal", and configure it to use your class)
    In your route prefix class, put something like this

    PHP:
    class MyAddon_RoutePrefix implements XenForo_Route_Interface {
        public function 
    match($routePathZend_Controller_Request_Http $requestXenForo_Router $router) {
            
    $page $routePath// it will be lorem/ipsum/dolor/blah blah
            
    return $router->getRouteMatch('MyAddon_Controller','open',$page);
        }

        public function 
    buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams) {
            
    // do something interesting here if you want
        
    }
    }
    And use this in your controller
    PHP:
    $page $this->_routeMatch->getMajorSection();
    A little bit over complicated :(
     
  10. Mythotical

    Mythotical Well-Known Member

    Jaxel, did you ever get this figured out?
     
  11. account8226

    account8226 Guest

    Any way to do it ?
     

Share This Page