Cakephp Classroom image

osdyui
 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21|Last
Lessons:-Core Libraries

were no errors and the other callbacks did not change the state of the order itself. For those cases you use
priorities.
Priorities are handled using a number associated to the callback itself. The higher the number, the later the
method will be fired. Default priority for all callbacks and listener methods are set to 10. If you need your
method to be run before, then using any value below this default will help you do it, even setting the priority
to 1 or a negative value should work. On the other hand if you desire to run the callback after the others,
using a number above 10 will do.
If two callbacks happen to be allocated in the same priority queue, they will be executed with a FIFO policy,
the first listener method to be attached is called first and so on. You set priorities using the attach method
for callbacks, and declaring it in the implementedEvents function for event listeners:
// Setting priority for a callback
$callback = array($this, ’doSomething’);
$this->getEventManager()->attach($callback, ’Model.Order.afterPlace’, array(’priority’ => 2));
// Setting priority for a listener
class UserStatistic implements CakeEventListener {
public function implementedEvents() {
return array(
’Model.Order.afterPlace’ => array(’callable’ => ’updateBuyStatistic’, ’priority’ );
}
}
As you see, the main difference for CakeEventListener objects is that you need to use an array for specifying
the callable method and the priority preference. The callable key is an special array entry that the manager
will read to know what function in the class it should be calling.
Getting event data as function params Some developers might prefer having the event data passed as
function parameters instead of receiving the event object. While this is an odd preference and using the
event object is a lot more powerful, this was needed to provide backwards compatibility with the previous
event system and to offer seasoned developers an alternative to what they were used to.
In order to toggle this option you have to add the passParams option to the third argument of the attach
method, or declare it in the implementedEvents returned array similar to what you do with priorities:
// Setting priority for a callback
$callback = array($this, ’doSomething’);
$this->getEventManager()->attach($callback, ’Model.Order.afterPlace’, array(’passParams’ => // Setting priority for a listener
class UserStatistic implements CakeEventListener {
public function implementedEvents() {
return array(
’Model.Order.afterPlace’ => array(’callable’ => ’updateBuyStatistic’, ’passParams’ );
}
public function updateBuyStatistic($orderData) {
// ...

 
 
 

osdyui

Skills    Cakephp

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)