当前位置: 首页>>代码示例>>PHP>>正文


PHP Alias::applyAliasMulti方法代码示例

本文整理汇总了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;
 }
开发者ID:kevthunder,项目名称:cake-shop,代码行数:74,代码来源:shop_order.php


注:本文中的Alias::applyAliasMulti方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。