After reading through the definitive guide and searching the forums I am still confused with using actions.
Would it be possible to have SettingsController called from AccountController…something like this, for example…
<?php
class AccountController extends CController
{
public function actions()
{
return array(
// captcha action renders the CAPTCHA image
// this is used by the contact page
'settings'=> 'application.controllers.SettingsController'
);
}
// ...other account functions...
}
And then in the settings controller to have something like
<?php
class SettingsController extends CController
{
public function actionPassword()
{
// ...
}
public function actionEmail()
{
// ...
}
}
So then I would be able to do account/settings/password.
Or would the best thing to do is create a custom url for settings/password to refer to account/settings/password ?
actions() method only used to collect actions defined in their own classes (which always extend CAction), and not to refer to action in other controllers.
There is no need to point to other controller’s actions. If you want to customize the url, you can use urlManager instead.
To the OP: You’re misunderstanding how controllers work. A URL always routes to a controller/action pair. Always. Hence:
http://hostname/index.php?r=post/edit
or
http://hostname/post/edit
if you have fixed the URLs with
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
...
}
If you want to use a different URL scheme, then you do so by adding rules to the urlManager just mentioned. That’s where URL things are done; not in controllers.
So, to do what you want you need to settle on an appropriate controller name, say AccountSettingsController, and create an action within it called actionPassword.