本文整理匯總了PHP中Cake\ORM\Table::errors方法的典型用法代碼示例。如果您正苦於以下問題:PHP Table::errors方法的具體用法?PHP Table::errors怎麽用?PHP Table::errors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cake\ORM\Table
的用法示例。
在下文中一共展示了Table::errors方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: resetSlugs
/**
* ResetSlugs method.
*
* Regenerate all slugs. On large dbs this can take more than 30 seconds - a time
* limit is set to allow a minimum 100 updates per second as a preventative measure.
*
* Note that you should use the Reset behavior if you need additional functionality such
* as callbacks or timeouts.
*
* @param array $params
* @return bool Success
*/
public function resetSlugs($params = [])
{
if (!$this->_table->hasField($this->_config['field'])) {
throw new Exception('Table does not have field ' . $this->_config['field']);
}
$defaults = ['page' => 1, 'limit' => 100, 'fields' => array_merge([$this->_table->primaryKey()], $this->_config['label']), 'order' => $this->_table->displayField() . ' ASC', 'conditions' => $this->_config['scope'], 'overwrite' => true];
$params = array_merge($defaults, $params);
$count = $this->_table->find('all', compact('conditions'))->count();
$max = ini_get('max_execution_time');
if ($max) {
set_time_limit(max($max, $count / 100));
}
$this->_table->behaviors()->Slugged->config($params, null, false);
while ($records = $this->_table->find('all', $params)->toArray()) {
foreach ($records as $record) {
$record->isNew(true);
$options = ['validate' => true, 'fieldList' => array_merge([$this->_table->primaryKey(), $this->_config['field']], $this->_config['label'])];
if (!$this->_table->save($record, $options)) {
throw new Exception(print_r($this->_table->errors(), true));
}
}
$params['page']++;
}
return true;
}