controller-events

Behavior/Event for CController to raise&handle 4 events: beforeAction(), afterAction(), beforeRender(), afterRender().
1 follower

EControllerBehavior is a behavior that can handle controller events:

  • beforeAction
  • afterAction
  • beforeRender
  • afterRender

Your controller should extend EController. You create a behavior by extending EControllerBehavior and implement one of above listed methods. Inside a handler you have $event instance, which has following properties:

  • in beforeRender: $event->view.
  • in afterRender: $event->view and $event->output.
  • in beforeAction: $event->action.
  • in afterAction: $event->action.

Also, in beforeAction and beforeRender you can set $event->isValid property to allow or deny corresponding processing.

Also, it supports actions inside behaviors.

Example

// main.php
    'import' => array('ext.controller-events.*'),
// CrudController.php
<?php
class CrudController extends EControllerBehavior {
    public function beforeAction(EControllerEvent $event) {
        if (rand(0, 1))
            $event->isValid = false;
    }
}

Resources ΒΆ

Be the first person to leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet