本文整理汇总了PHP中AppModel::clear方法的典型用法代码示例。如果您正苦于以下问题:PHP AppModel::clear方法的具体用法?PHP AppModel::clear怎么用?PHP AppModel::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppModel
的用法示例。
在下文中一共展示了AppModel::clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterSave
public function afterSave(\Model $model, $created, $options = array())
{
parent::afterSave($model, $created, $options);
$class = get_class($model);
if (isset($model->data['MultiLanguage'][$class])) {
$data = array();
foreach ($model->data['MultiLanguage'][$class] as $field => $value) {
foreach ($value as $lang => $text) {
$data[$lang][$field] = $text;
}
}
$dataExisted = Hash::combine($model->query('SELECT MultiLanguage.* FROM multilanguage_' . $model->useTable . ' MultiLanguage WHERE object_id = "' . Sanitize::escape($model->getID()) . '"'), '{n}.MultiLanguage.lang_code', '{n}.MultiLanguage.id');
foreach ($data as $lang => $object) {
if (isset($dataExisted[$lang])) {
$object['id'] = $dataExisted[$lang];
}
$object['object_id'] = $model->getID();
$object['lang_code'] = $lang;
$multiObj = new AppModel();
$multiObj->useTable = 'multilanguage_' . $model->useTable;
$multiObj->clear();
$multiObj->save($object, array('validate' => false, 'callbacks' => false));
}
}
}
示例2: saveDataFromArray
static function saveDataFromArray($object, $listData, $listKey)
{
if (count($listData) == 0) {
return true;
}
$id = $object->getID();
$msgError = '';
$listLanguage = array_keys(Configure::read('MultiLanguage.fallback') + Configure::read('MultiLanguage.list'));
$mapping = Configure::read('MultiLanguage.app_mapping_list');
for ($ii = 1; $ii < count($listData[0]); $ii++) {
$listData[0][$ii] = isset($mapping[strtolower($listData[0][$ii])]) ? $mapping[strtolower($listData[0][$ii])] : $listData[0][$ii];
}
$data = $listData[0];
if (strtoupper($data[0]) != 'KEY' || count(array_intersect($listLanguage, $data)) != count($listLanguage)) {
$msgError = __('The header of Excel file shoud be in format') . ': Key';
foreach ($listLanguage as $lang) {
$msgError .= ', ' . $lang;
}
} else {
$listLanguage = $data;
$numField = count($listLanguage);
$dataMultiLang = array();
for ($row = 1; $row < count($listData); $row++) {
$data = $listData[$row];
$num = count($data);
if ($num != $numField || !in_array($data[0], $listKey)) {
$msgError .= __('Cannot import line %s', $row) . "<br />";
} else {
for ($c = 1; $c < $num; $c++) {
$dataMultiLang[$listLanguage[$c]][$data[0]] = $data[$c];
}
}
}
}
$fallback = array_keys(Configure::read('MultiLanguage.fallback'));
if (isset($dataMultiLang[$fallback[0]])) {
$row = $dataMultiLang[$fallback[0]];
$row['id'] = $id;
$object->clear();
$object->save($row, false);
unset($dataMultiLang[$fallback[0]]);
}
$model = new AppModel();
$model->useTable = 'multilanguage_' . $object->useTable;
foreach ($dataMultiLang as $lang => $row) {
$objMultiLang = $model->findByObjectIdAndLangCode($id, $lang);
if (isset($objMultiLang['AppModel']['id'])) {
$row['id'] = $objMultiLang['AppModel']['id'];
}
$row['lang_code'] = $lang;
$row['object_id'] = $id;
$model->clear();
$model->save($row, false);
}
return $msgError;
}