Creating routes for controllers in subdirectories in Kohana 3.2

53 Views Asked by At

My question is almost similar to this question. His goes 2 more directories deep and mine is just 1. That question was unanswered too.

This is the directory i wish to create:

classes
|--controller
  |--tests
    |--general.php

All i want to do is for a route to recognize that I'm accessing a controller in a subdirectory. Something like these:

localhost/stackoverflows/tests/general
localhost/stackoverflows/tests/general/index
localhost/stackoverflows/tests/general/lambda
localhost/stackoverflows/tests/general/lambda/parameter_1

I tried all the other solutions out there but nothing works. Not one tutorial. Or an answer to a question from a forum that was ACTUALLY tested. Even on the official kohana forum site. So i'm trying my luck here in SO.

Thanks in advance!

1

There are 1 best solutions below

2
mrBrown On

To save a controller in that folder structure you should name your controller like Controller_Tests_General, and it should be placed in the folder /controller/tests/general. There you can create your actions. See example below.

Class Controller_Tests_General extends Controller
{

    public function action_index()
    {
        // your code here
        die('Do I end up here?');
    }

    public function action_lamdba()
    {
        // your code here
        // id should be defined in your bootstrap file as a Route to work like this.
        $parameter_id = $this->request->param('id');
    }
}