你可以优先触发对象回调类似事件回调。优先级值的处理和订单触发解释相同。这里是如何指定优先级在申报时间:
class SomeController {
public $components = array(
'Foo', //Foo gets default priority 10
// Bar's callbacks are triggered before Foo's
'Bar' => array('priority' => 9)
);
public $helpers = array(
// Cache's callbacks will be triggered last
'Cache' => array('priority' => 12),
'Asset',
'Utility' //Utility has priority 10 same as Asset and its callbacks
//are triggered after Asset's
);
}
class Post {
public $actsAs = array(
'DoFirst' => array('priority' => 1),
'Media'
);
}
动态加载对象集合时您可以指定优先级如下:
$this->MyComponent = $this->Components->load(
'MyComponent',
array('priority' => 9)
);
你也可以在运行时改变优先级使用ObjectCollection::setPriority()函数:
//For a single object
$this->Components->setPriority('Foo', 2);
//For multiple objects
$this->Behaviors->setPriority(array('Object1' => 8, 'Object2' => 9));