[solved]controller/subcontroller via gii?

I have already generated a council model-view-controller and have a bunch of views for that

that are accessed from /council

now I want to generate a new set of views for the president and put it under council so it would be accessed from

/council/president

so in gii as suggested by the help popup I used the controller generator with controller ID

council/president

and left Base Class as default Controller

and Action IDs as default index

gii happily generates these:

controllers/council/PresidentController.php

views/council/president/index.php

and offers me to try it now:

"The controller has been generated successfully. You may try it now."

but when the link is clicked on it generates a 404 with message

The system is unable to find the requested action "president".

looking at the error log we have


exception 'CHttpException' with message 'The system is unable to find the

requested action "president".' in

/var/www/localhost/yii/yii-1.1.8.r3324/framework/web/CController.php:477

Stack trace:

#0

/var/www/localhost/yii/yii-1.1.8.r3324/framework/web/CController.php(262):

CController->missingAction('president')

#1

/var/www/localhost/yii/yii-1.1.8.r3324/framework/web/CWebApplication.php(277):

CController->run('president')

#2

/var/www/localhost/yii/yii-1.1.8.r3324/framework/web/CWebApplication.php(136):

CWebApplication->runController('council/preside...')

#3

/var/www/localhost/yii/yii-1.1.8.r3324/framework/base/CApplication.php(158):

CWebApplication->processRequest()

#4 /var/www/localhost/htdocs/index.php(31): CApplication->run()

#5 {main} REQUEST_URI=/council/president

which mystifies me as everything is there. It just won’t run for some reason.

What am I missing?

Looks like Yii is interpreting "council" as your controller, and "president" as your action. Is "council" your module? How does your url looks like?

It’s not a module. But the error message does look like it is trying for the council controller except that in the error log it looks to be trying to get the right controller


CWebApplication->runController('council/preside...')

The URL is as Gii suggested for me /council/president

The Gii help popup suggests that entering admin/user for the controller will generate admin/UserController.php and that is exactly what it does for council/president Gii makes a new folder protected/controllers/council/PresidentController.php

The Controller documentation section 2 suggests the same thing


If the ID is in the format 'path/to/xyz', the controller class name is assumed to be XyzController and the corresponding class file is protected/controllers/path/to/XyzController.php. For example, a controller ID admin/user would be mapped to the controller class UserController and the class file protected/controllers/admin/UserController.php. If the class file does not exist, a 404 CHttpException will be raised.

which if it was doing as you suggest would mean that admin/UserController would try to use the AdminController at least that is how I read the docs to mean.

Looks like I did not understand. :blink:

I tried a different approach. first I created banana/president from Gii and it worked as expected with a controller at controllers/banana/PresidentController.php

next with Gii created controller banana which works but now banana/president gives the action not found error so I guess you can’t nest controllers like that.