The setTarget method in Zend\Mvc\MvcEvent class allows you to set the target for the event. This can be useful for modifying the target object, which is passed to the event manager.
Example:
Let's say you have a module that hooks into the onDispatch event in the MVC event manager. You can use the setTarget method to modify the target object before it is passed to your module.
Code:
use Zend\Mvc\MvcEvent;
class MyModule { public function onDispatch(MvcEvent $e) { // get the target object $target = $e->getTarget();
// modify the target object $target->setFoo('bar');
// set the modified target back $e->setTarget($target); } }
In this example, the onDispatch event is called whenever a controller is dispatched. The $target variable represents the controller object. We use the setFoo method to modify the controller, and then pass it back to the event manager using setTarget.
Package Library:
Zend\Mvc\MvcEvent is part of the Zend Framework, which is a package library for PHP.
PHP Zend\Mvc MvcEvent::setTarget - 21 examples found. These are the top rated real world PHP examples of Zend\Mvc\MvcEvent::setTarget extracted from open source projects. You can rate examples to help us improve the quality of examples.