Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8259319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:49:56+00:00 2026-06-08T02:49:56+00:00

I’m creating a Kohana module, and creating a route dynamically within that module. I’d

  • 0

I’m creating a Kohana module, and creating a route dynamically within that module. I’d like the route to take precedence over routes in the rest of the app. (Especially of the default, catch-all route).

Any thoughts on how to do this?

Thanks!

======
Update:

I think I forgot to mention that I’m loading the module dynamically, like this:

Kohana::modules(array_merge(array($module_name=>$directory), Kohana::modules()));

and then I’m running an HMVC request for the module, like so:

$response = Request::factory('versioned-api')
            ->method('POST')
            ->secure(true)
            ->post(array('data'=>serialize($request))) // Performing a straightforward POST
            ->execute();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:49:58+00:00Added an answer on June 8, 2026 at 2:49 am

    Some background on Kohana (as of 3.2) module and routing precedence:

    1. Modules are initialized in the order Kohana::modules is called. This is important based on the desired precedence for routes. In your example, Kohana::modules(array_merge(array($module_name=>$directory), Kohana::modules()));, any modules already placed in Kohana::modules() have already been initialized. Even though you are merging a new module to the beginning of the list, modules are initialized as Kohana::modules() is called. If you look at “system/classes/kohana/core.php” line 565, you will notice that “init.php” is required once (if present in the module).
    2. Routes are matched in the order they are added. They are also overwritten if the same route name is used.

    In summary, there is no way natively in Kohana to push a Route to the beginning of the list. Of course, guaranteeing that the module in question is loaded first would solve your problem (as long as the route is not overwritten later on). If you can transparently extend Route, below is how you can accomplish this if the module is loaded later on by prepending the route to the beginning of the stack:

    GitHub Gist (including unit test): https://gist.github.com/3148737

    <?php defined('SYSPATH') or die('No direct script access.');
    /**
     * Route transparently extended. Place in "classes" directory of Kohana 3+ application or module.
     */
    class Route extends Kohana_Route
    {
        /**
         * Prepend Route to beginning of stack. If name already exists further in the stack, it is 
         * removed.
         * 
         *  Route::prepend('default', '(<controller>(/<action>(/<id>)))')
         *      ->defaults(array(
         *          'controller' => 'welcome'
         *      ));
         * 
         * @static
         * @access  public
         * @param   string   route name
         * @param   string   URI pattern
         * @param   array    regex patterns for route keys
         * @return  Route
         */
        public static function prepend($name, $uri_callback = NULL, $regex = NULL)
        {
            // Ensure entry does not already exist so it can be added to the beginning of the stack
            if (isset(Route::$_routes[$name]))
            {
                unset(Route::$_routes[$name]);
            }
    
            // Create reference
            Route::$_routes = array_merge(array($name => NULL), Route::$_routes);
    
            // Overwrite reference
            return Route::$_routes[$name] = new Route($uri_callback, $regex);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.