Controller In Subdirectory


I’m very new to yii and everything went smooth so far. I’m really satisfied with the learning-curve of this framework.

But now I stumbled upon a problem that I don’t understand.

I’ve created a subdirectory called “api” in the protected/controllers/ folder with an UserController in it.

It looks like:


--------- controllers/

-------------------- api/

------------------------ UserController.php

in config/main.php I’ve added that folder to the autoloader:






I’ve also setup two rules for it in the urlmanager:





When accessing the url /api/1.0/user/login yii tolds me that the action user can’t be found.

Any idea what’s happening? For me it looks like yii tries to access “api” as Controller and <controller> as action.

I’m afraid this is how it works.

To resolve this issue you can either use a nice module system (docs) or use some hacks like class-based actions (not so good)

Also see this post

Maybe this will help:

But it looks like an "api" module will suit better there.

Hmm… I think what OP does should work. I have a controller in a subdirectory and yii can call it without any problem. I’m not sure what makes OP’s issue doesn’t work, but you may try to call it directly /api/user/login, does it work or not?

I’ve found the problem. Never name a controller like your subdirectory. I had a obsolete ApiController.php file in the controllers folder. -_-

Thank you guys. It’s great too see the community that active here.