當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。