Static routes not working in some cases

Hello guys,

I'm trying to use a static route to render a private member page in a plugin and it doesn't working.

Could someone help me?

I have a plugin called ChannelManagement, a controller called privateChannel.php and a view called private.phtml.
Follows the code:

In the plugin:

public function actionPrivateChannelRoute($routes) {
$routes['private-channel'] = new Route(array(
'path' => 'members/private',
'location' => dirname(__FILE__).'/privateChannel.php',
));
return $routes;
}


In the privateChannel.php


<?php
$this->view->options->viewFile = dirname(__FILE__)."/private.phtml";

?>


And finally the view:

<?php $this->setLayout('full'); ?>

<div class="row">
<div class="form-container col-md-6 col-center">
<h1><?=Language::GetText('public_channel')?></h1>
<p><?=Language::getText('public_channel_message')?></p>
</div>
</div>


When I try to access {url-base}/members/private it returns 404 error.

Comments

  • What does the "load" method look like in your plugin? Is the plugin installed and enabled in the Admin Panel?
  • Among other events and filters, the "load" method has the following code:


    Plugin::attachFilter('router.static_routes', array($this, 'actionPrivateChannelRoute'));
  • Seems strange, I just copied and pasted your code into a new plugin and it worked fine. Though instead of "$this" I used "__CLASS__" in the attachFilter call.

    Are you 100% sure the plugin is installed and enabled in Admin Panel -> Plugins -> Plugins?
  • Sure.
    This plugin is used to manage users which are set as channels of our video site.
    I have the static route in another plugin and it works fine.
  • There is probably something interfering with either the new route or the new plugin, which is preventing it from doing it's thing. I would completely disable all other plugins and isolate this one to see if it works. Additionally, also try renaming the plugin/directory/class to something else as well as the route's URL path.

    Trial and error is your best friend in this case.
  • Thanks.
    I was thinking that it could be a problem related with the route /members and the regex.
    For example, it would be redirecting to the members/regex instead of members/private.


    =D
This discussion has been closed.