1

So it seems like this is a routing issue, but I cannot access my controller from another controller. Here is my controller structure:

controllers
--api
----v1
------exercises.php
------helpers.php
------routines.php
--groups
----admin.php
----users.php
--reports.php
--totals.php

So the issue is accessing any of my api controllers from another controller. I can hit any of them just fine by hitting a url like mysite.com/index.php/api/v1/routines/routine/1, but I accessing them from another controller is out of the question.

Here's an example:

If I want to access method() from the Groups_Users controller, using my Reports controller, all I would do is this:

Users::method()

However, if I want to access api_method() from the Api_V1_Exercises controller, using any other controller, I would think that it would be the same, like this:

Exercises::api_method()

This DOES NOT work, and I have NO idea why... The names of the classes are unique, so I really don't know what is going on.

Also, in the controllers that are in sub-folders, they are extending the base controller like everything else, but they have a \ before it, like this:

class Api_V1_Exercises_Controller extends \Base_Controller

What am I doing wrong? I really could use some help figuring this one out.

Laurence
  • 58,936
  • 21
  • 171
  • 212
  • Unless I'm going nuts, your class name would be Api_V1_Exercises_Controller::method. I'm assuming your users.php is class users extends \Base_Controller? To help troubleshoot the issue, you could use get_class() on a declared variable. For example: $bar = new foo(); echo get_class($bar); – Telshin Sep 09 '13 at 20:35
  • You are correct that the name of the Controller would be Api_V1_Excercises_Controller (as stated above), but calling a controller from within another controller, you only use the piece right before '_Controller', so in this case, 'Exercises' to call a method. That is how it is done in all of my other controllers, but they are only 1 folder deep, or in the base of /controllers, rather than 2 folders deep. – Nicholaus Chipping Sep 11 '13 at 04:06
  • I'll have to setup a test of this and find out a better solution. Were you able todo anything with get_class()? – Telshin Sep 11 '13 at 19:45
  • Perhaps it's too late but you could just setup the autoloader folders to include specifically the v1 folder? – Panais Dec 28 '13 at 22:04

0 Answers0