CWidget::actions() usecases and examples

Hello guys,

Could someone provide examples of using CWidget::actions()?

I read docs, but i'm still misunderstanding 2 things:

  1. How can i call (inside of widget) action which is imported via CWidget::actions() and implemented as CAction?

  2. Where have action to be implemented if i want to provide it with my widget to use in controller?

My idea is to declare LoginAction and then to use it inside UsersController and inside LoginWidget. Is that possible?

CWidget::actions() is mainly used when you have a lot of actions associated with a widget. In your case you don't need it. You may refer to the login portlet in the blog demo.

The relevant documentation about using CWidget::actions() is in the API manual about CWidget::actions() and CController::actions().

To answer your question,

  1. the route for a widget action is in the form of: controllerID/actionPrefix.actionID

  2. You may place the action class anywhere (e.g. components). You just need to specify the 'class' option correctly when you declare CWidget::actions()

Now its clear for me,  thank you :slight_smile: