Search code examples
phpcodeigniterroutespyrocms

PYROCMS custom module routing is not working


This is my routing code.

 $route['news(/:num)?'] = 'news/index$1';
 $route['events(/:num)'] = 'news/events$1';

this is my Controller code.

<?php

if (!defined('BASEPATH'))
     exit('No direct script access allowed');

class News extends Public_Controller
{
   public function __construct()
   {
      parent::__construct();

      parent::__construct();
      $this->lang->load('news');
      $this->load->helper('url');
  }


  public function index()
  {
        $data = 'index call';
       // Build the page
       $this->template->title($this->module_details['name'])
            ->build('index', $data);
  }

  public function events()
  {
      $data = 'events call';
      // Build the page
      $this->template->title($this->module_details['name'])
            ->build('index', $data);
  }
}

http://example.com/news this url is working.

http://example.com/events this url is not wokring.


Solution

  • I stacked before same issue and found the solution.

    Solution is modification the application/config/routes.php file.

    Because of module routes working only when it's running. You have to routes file that allways running, that file is system routes.php So first segment of routes should be module name in module routes file.

    For /news/722/hello-world/ url:

    $route['news(/:num)?'] = 'news/index$1'; // This will work
    
    $route['events(/:num)'] = 'news/events$1'; // This wont work
    

    If you want to change routing events, you have to modify application/config/routes.php

    My discussion PyroCMS Forum:

    https://forum.pyrocms.com/discussion/25301/navigation-link-to-module-with-custom-routing