本文整理汇总了PHP中Cake\ORM\Table::processAction方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::processAction方法的具体用法?PHP Table::processAction怎么用?PHP Table::processAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Table
的用法示例。
在下文中一共展示了Table::processAction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* Process action.
*
* @param Table $table
* @param $action
* @param array $ids
* @param array $options
* @return \Cake\Network\Response|void
*/
public function process(Table $table, $action, array $ids = [], array $options = [])
{
$idsCount = count($ids);
$options = Hash::merge($this->_config, $options);
$_options = ['messages' => $this->__setupMessages($idsCount)];
$options = Hash::merge($_options, $options);
$redirect = $options['redirect'];
$messages = $options['messages'];
if (!$action) {
$this->Flash->error($messages['noAction']);
return $this->_controller->redirect($redirect);
}
if ($idsCount == 0) {
$this->Flash->error($messages['noChose']);
return $this->_controller->redirect($redirect);
}
$behaviors = $table->behaviors();
if (!in_array('BulkProcess', $behaviors->loaded())) {
$behaviors->load('Union/Core.BulkProcess');
}
$event = Event::dispatch($this->_getEventName($action, 'bulkBefore'), $this->_controller, ['ids' => $ids]);
if (is_array($event->result)) {
$ids = $event->result;
if (count($ids) == 0) {
$this->Flash->error($messages['noChose']);
return $this->_controller->redirect($redirect);
}
$messages = $this->__setupMessages(count($ids));
}
$process = $table->processAction($action, $ids);
if ($process) {
if (!empty($messages[$action])) {
$message = $messages[$action];
} else {
$message = __d('union', '{0} processed', Inflector::humanize($this->_controller->name));
}
Event::dispatch($this->_getEventName($action), $this->_controller, ['ids' => $ids]);
$this->Flash->success($message);
return $this->_controller->redirect($redirect);
}
$this->Flash->error(__d('union', 'An error occurred'));
return $this->_controller->redirect($redirect);
}