0
votes

This question is not a duplicate of codeigniter get all declared routes

I have to get all my CodeIgniter framework routes for all the controllers. I have not defined any routing under routes.php, I am just using the route like

https://domain/controller/action

Now I want to get my all route like

https://domain/user/login

https://domain/user/logout 

and so on...

Is there any way to get my all routes?

I hope you understand what I want to say!

1
As per my understanding you want to read all your application controller action right? - K.K
@B.K right Can you please help me to achieve this ..?? - Mannu saraswat
Have you tried anything? - K.K
Yes I have found a way to get all routes from a particular controller, trying something which gives me all routes from all controller - Mannu saraswat

1 Answers

1
votes

Correct me if I am not wrong. You want to fetch all methods of given class and/or all classes along with their methods in given controller directory.

This way you will be having all available routes for the application/controllers/User.php say

You can achieve the same by doing as follow.

You can use Codeigniter Library named List.php from source code at Gist here

You can use this library to list all controllers and methods.

Usage

You can fetch controllers list as below

function index()
{
        //  Fetch list of controllers 

        $endpoints  =   array_keys($this->lists->getControllers());

        print_r($endpoints);


}

You can fetch list of methods inside any given controllers as below:

function list_routes($endpoint='')
{
        if($endpoint=='')
            {
                die('Error');
            }

            $endpoint =     ucfirst($endpoint);
            $methods  =     $this->lists->getControllers();

            print_r($methods);
}

If you want to change the default folder from /controllers/ to anything else, you can either modify List.php function to extend and pass the dynamic parameter to setControllers function at

foreach(glob(APPPATH . 'YOUR_FOLDER_HERE') as $controller) {
    ###
}

I am using the Above solution to fetch and automate some API documentation where I fetch all endpoints and routes along with comments to display in our developer panel.

Please feel free to reach me if having any doubts or question regarding the same.