本文整理汇总了PHP中Alias::applyAliasMulti方法的典型用法代码示例。如果您正苦于以下问题:PHP Alias::applyAliasMulti方法的具体用法?PHP Alias::applyAliasMulti怎么用?PHP Alias::applyAliasMulti使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Alias
的用法示例。
在下文中一共展示了Alias::applyAliasMulti方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
function beforeSave()
{
$named = isset($this->data[$this->name]);
if ($named) {
$data = $this->data[$this->name];
} else {
$data = $this->data;
}
if (isset($data['id'])) {
$id = $data['id'];
} else {
$id = $this->id;
}
if (!empty($data['use_shipping'])) {
if (!empty($data['shipping_address'])) {
$shipping_data = $data;
} elseif (!empty($id)) {
$shipping_data = $this->read(null, $id);
$shipping_data = $shipping_data[$this->name];
}
if (!empty($shipping_data)) {
$prefix_from = "shipping_";
$prefix_to = "billing_";
foreach ($shipping_data as $key => $val) {
if (substr($key, 0, strlen($prefix_from)) == $prefix_from) {
$sufix = substr($key, strlen($prefix_from));
//if(empty($data[$prefix_to.$sufix])){
$data[$prefix_to . $sufix] = $shipping_data[$key];
//}
}
}
}
}
if (!empty($data['use_billing'])) {
if (!empty($data['billing_address'])) {
$billing_data = $data;
} elseif (!empty($id)) {
$billing_data = $this->read(null, $id);
$billing_data = $billing_data[$this->name];
}
if (!empty($billing_data)) {
$prefix_from = "billing_";
$prefix_to = "shipping_";
foreach ($billing_data as $key => $val) {
if (substr($key, 0, strlen($prefix_from)) == $prefix_from) {
$sufix = substr($key, strlen($prefix_from));
//if(empty($data[$prefix_to.$sufix])){
$data[$prefix_to . $sufix] = $billing_data[$key];
//}
}
}
}
}
App::import('Lib', 'Shop.SetMulti');
$both_keys = SetMulti::pregFilterKey('/^both_/', $data);
foreach ($both_keys as $key => $val) {
$key = preg_replace('/^both_/', '', $key);
if (empty($data["billing_" . $key])) {
$data["billing_" . $key] = $val;
}
if (empty($data["shipping_" . $key])) {
$data["shipping_" . $key] = $val;
}
}
$fieldsToAlias = array('billing_country' => 'country', 'billing_region' => 'region', 'shipping_country' => 'country', 'shipping_region' => 'region');
App::import('lib', 'Shop.Alias');
$data = Alias::applyAliasMulti($data, $fieldsToAlias);
if ($named) {
$this->data = array($this->name => $data);
} else {
$this->data = $data;
}
return true;
}