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


PHP CMap::mergeWith方法代码示例

本文整理汇总了PHP中CMap::mergeWith方法的典型用法代码示例。如果您正苦于以下问题:PHP CMap::mergeWith方法的具体用法?PHP CMap::mergeWith怎么用?PHP CMap::mergeWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CMap的用法示例。


在下文中一共展示了CMap::mergeWith方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: locate

 /**
  * 
  * Locates IP information
  * @param string $ip address. If null, it will locate the IP of request
  */
 public function locate($ip = null)
 {
     if (null === $ip) {
         $ip = $_SERVER['REMOTE_ADDR'];
     }
     $host = str_replace('{IP}', $ip, $this->_service);
     $host = str_replace('{CURRENCY}', $this->_currency, $host);
     $response = $this->fetch($host);
     if (!is_null($response) && is_array($response)) {
         $this->_data->mergeWith($response);
         $this->_data->add('ip', $ip);
         return true;
     }
     return true;
 }
开发者ID:2amigos,项目名称:egeoip,代码行数:20,代码来源:EGeoIP.php

示例2: relations

 public function relations()
 {
     $map = new CMap(parent::relations());
     $nrelation = array('images' => array(self::HAS_MANY, 'Image', 'model_id', 'condition' => 'images.model_name = \'Category\''));
     $map->mergeWith($nrelation);
     return $map;
 }
开发者ID:Rudianasaja,项目名称:cycommerce,代码行数:7,代码来源:Category.php

示例3: addFlashMessage

 /**
 * @param $message
   // пример использования в контроллере:
   // $err = array('test1','test2'); // складываем ошибки в массив // можно доделать с использовать _addError как в контроллере orders/cart если запрос через ajax
   // Yii::app()->user->setFlash('messages_red', $err);
   // $this->addFlashMessage($model->getErrors(),'red'); // до кучи берем ошибки модели
   // Если была/были впереди ошибка/ошибки, показываем все
 */
 public function addFlashMessage($message, $style = 'success')
 {
     $currentMessages = Yii::app()->user->getFlash('error');
     if (!is_array($currentMessages)) {
         $currentMessages = array($currentMessages);
     }
     $map = new CMap($currentMessages);
     if (is_array($message)) {
         foreach ($message as $mes) {
             if (is_array($mes)) {
                 $map->mergeWith($mes);
             } else {
                 $map->mergeWith(array($mes));
             }
         }
     } else {
         $map->mergeWith(array($message));
     }
     $messages = $map->toArray();
     Yii::app()->user->setFlash($style, $messages);
 }
开发者ID:Aplay,项目名称:Fastreview_site,代码行数:29,代码来源:Controller.php

示例4: mergeWith

 /**
  * Merges iterable data into the map.
  *
  * Existing elements in the map will be overwritten if their keys are the same as those in the source.
  * If the merge is recursive, the following algorithm is performed:
  * <ul>
  * <li>the map data is saved as $a, and the source data is saved as $b;</li>
  * <li>if $a and $b both have an array indexed at the same string key, the arrays will be merged using this algorithm;</li>
  * <li>any integer-indexed elements in $b will be appended to $a and reindexed accordingly;</li>
  * <li>any string-indexed elements in $b will overwrite elements in $a with the same index;</li>
  * </ul>
  *
  * @param mixed $data the data to be merged with, must be an array or object implementing Traversable
  * @param boolean $recursive whether the merging should be recursive.
  *
  * @throws CException If data is neither an array nor an iterator.
  */
 public function mergeWith($data, $recursive = true)
 {
     if (!$this->caseSensitive && (is_array($data) || $data instanceof Traversable)) {
         $d = array();
         foreach ($data as $key => $value) {
             $d[strtolower($key)] = $value;
         }
         return parent::mergeWith($d, $recursive);
     }
     parent::mergeWith($data, $recursive);
 }
开发者ID:phuluang,项目名称:rosewellmusic,代码行数:28,代码来源:CAttributeCollection.php

示例5: testRecursiveMergeWithTraversable

 public function testRecursiveMergeWithTraversable()
 {
     $map = new CMap();
     $obj = new ArrayObject(array('k1' => $this->item1, 'k2' => $this->item2, 'k3' => new ArrayObject(array('k4' => $this->item3))));
     $map->mergeWith($obj, true);
     $this->assertEquals(3, $map->getCount());
     $this->assertEquals($this->item1, $map['k1']);
     $this->assertEquals($this->item2, $map['k2']);
     $this->assertEquals($this->item3, $map['k3']['k4']);
 }
开发者ID:avtograd,项目名称:yii,代码行数:10,代码来源:CMapTest.php

示例6: testMergeWith

 public function testMergeWith()
 {
     $a = array('a' => 'v1', 'v2', array('2'), 'c' => array('3', 'c' => 'a'));
     $b = array('v22', 'a' => 'v11', array('2'), 'c' => array('c' => '3', 'a'));
     $c = array('a' => 'v11', 'v2', array('2'), 'c' => array('3', 'c' => '3', 'a'), 'v22', array('2'));
     $map = new CMap($a);
     $map2 = new CMap($b);
     $map->mergeWith($map2);
     $this->assertTrue($map->toArray() === $c);
     $array = array('key2' => $this->item1, 'key3' => $this->item3);
     $this->map->mergeWith($array, false);
     $this->assertTrue($this->map->getCount() == 3 && $this->map['key2'] === $this->item1 && $this->map['key3'] === $this->item3);
     $this->setExpectedException('CException');
     $this->map->mergeWith($this, false);
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:15,代码来源:CMapTest.php


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