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

Trying to create a public route...

Discussion in 'XenForo Development Discussions' started by Matthew Hawley, Jan 14, 2014.

  1. Matthew Hawley

    Matthew Hawley Well-Known Member

    I am trying to create a public route.

    This is my ControllerPublic/Directory.php code

    Code:
    <?php
    
    class CF_Directory_ControllerPublic_Directory extends XenForo_ControllerPublic_Abstract
    {
        public function actionIndex()
        {
            // send to template for display
            return $this->responseView('CF_Directory_Index', 'cf_directory_index', $viewParams);
    }
    This is my Route/Prefix/Directory.php code
    Code:
    <?php
    
    class CF_Directory_Route_Prefix_Index implements Xenforo_Route_Interface
    {
       public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
       {
         return $router->getRouteMatch('CF_Directory_ControllerPublic_Directory', $routePath, 'directory');
       }
    }
    [​IMG]

    When I go to .com/directory i get

    Route directory/ could not be found.

    Any suggestions?
     
  2. Milano

    Milano Well-Known Member

    Change Use class to build link to Never
     
  3. Matthew Hawley

    Matthew Hawley Well-Known Member

    Still doesn't work. :(
     
  4. Bob

    Bob Well-Known Member

    you named your route file Directory.php, yet your class and route use CF_Directory_Route_Prefix_Index, so either change the class and route to CF_Directory_Route_Prefix_Directory or change the file name to Index.php
     
    Matthew Hawley and Liam W like this.
  5. Liam W

    Liam W Well-Known Member

    Class name should correspond to the path of the PHP file relative to the library/ directory (unless using namespaces, when the fully qualified class name should correspond to the path of the PHP file...)

    Liam
     
  6. Matthew Hawley

    Matthew Hawley Well-Known Member

    Thanks Bob! I'm getting somewhere. Now I have this error.

    Here is the code.

    Code:
    <?php
    
    class CF_Directory_Route_Prefix_Directory implements Xenforo_Route_Interface
    
    {
    
       public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
    
       {
    
         return $router->getRouteMatch('CF_Directory_ControllerPublic_Directory', $routePath, 'directory');
    
       }
    
    }
    @Lawrence @Jeremy @Jake Bunce
     
    Last edited: Jan 14, 2014
  7. Jeremy

    Jeremy XenForo Moderator Staff Member

    Insistently tagging someone isn't going to get you help faster, it can actually become quite annoying.

    Although, you have mismatched braces within your controller. You may want to read and google errors, you'll be surprised what you can learn on the internet. Also, it'd help if you would reference and/or post the files with the actual error in them.
     
  8. Lawrence

    Lawrence Well-Known Member

    Sorry, I didn't receive an alert that I was tagged, odd.

    Your top code block in your first post, you are missing the closing } for your actionIndex.
     

Share This Page