• 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...

Matthew Hawley

Well-known member
#1
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');
   }
}


When I go to .com/directory i get

Route directory/ could not be found.

Any suggestions?
 

Bob

Well-known member
#4
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
 

Liam W

Well-known member
#5
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
 

Matthew Hawley

Well-known member
#6
Thanks Bob! I'm getting somewhere. Now I have this error.

Parse error: syntax error, unexpected $end, expecting T_FUNCTION in /home3/xxx/public_html/xxx/library/CF/Directory/ControllerPublic/Directory.php on line 9
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:

Jeremy

Well-known member
#7
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.
 

Lawrence

Well-known member
#8
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.