I keep running into a problem when organizing my controllers.
Often I have a controller file with several actions, some which take named parameters, which yii handles very well.
So I might have something like
class CarController extends Controller
{
public function actionDrive($road=‘highway51’)
{
…
}
public function actionPark($address=‘myhouse’)
{
…
}
}
Ok so that works fine and i can use urls like http://mysite.com/car/drive/highway71 , which is excellent.
HOWEVER
Sometimes there is a lot of code and there would be a benefit to putting each action as a separate controller.
Now yii actually handles this in an awesome way by allowing me to create for example a file Car/DriveController.php
with
class DriveController extends Controller
{
public $defaultAction = ‘work’;
public function actionWork($road=‘highway51’)
{
…
}
}
Now this will let me make the same call if i dont pass an arguement: http://mysite.com/car/drive
but it will fail if i try to pass it the named argument, e.g.: http://mysite.com/car/drive/highway44
I would love to be able to sometimes use this organization and use named arguments.
Perhaps another way to phrase this is that sometimes id like the subdirectory name to be sufficient for locating the controller, without having to specify an additional name that must be on the url path.
Is there a way to do this that I’m missing?