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


PHP Set::format方法代码示例

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


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

示例1: view

 /**
  * view method
  *
  * @param string $id
  * @return void
  */
 public function view($id = null)
 {
     $this->Upload->recursive = 0;
     $this->Upload->id = $id;
     if (!$this->Upload->exists()) {
         throw new NotFoundException(__('Invalid upload'));
     }
     $upload = $this->Upload->read(null, $id);
     $auth = $this->Auth->user();
     if (empty($auth)) {
         $this->Session->setFlash(__('You must be logged in to view this page.'));
         $this->redirect(array('controller' => 'users', 'action' => 'login'));
     }
     //Check to see if the user should be able to view the file
     if ($auth['id'] != $upload['Upload']['user_id']) {
         $this->Session->setFlash(__('You must be logged in to view this page.'));
         $this->redirect(array('controller' => 'users', 'action' => 'login'));
     }
     $this->paginate = array('Code' => array('limit' => 10));
     $upload['Code'] = $this->paginate('Code');
     //Paginate the code results
     $active_codes = $this->Upload->Code->find('count', array('conditions' => array('Code.upload_id' => $id, 'Code.active' => 1)));
     $all_codes = $this->Upload->Code->find('all', array('conditions' => array('Code.upload_id' => $id), 'fields' => array('Code.download_count')));
     $all_codes = Set::format($all_codes, '{0}', array('{n}.Code.download_count'));
     $total_downloads = array_sum($all_codes);
     $this->set(compact('upload', 'active_codes', 'total_downloads'));
 }
开发者ID:robksawyer,项目名称:grabitdown,代码行数:33,代码来源:UploadsController.php

示例2: testFormattingNullValues

 /**
  * testFormattingNullValues method
  *
  * @return void
  */
 public function testFormattingNullValues()
 {
     $data = array(array('Person' => array('first_name' => 'Nate', 'last_name' => 'Abele', 'city' => 'Boston', 'state' => 'MA', 'something' => '42')), array('Person' => array('first_name' => 'Larry', 'last_name' => 'Masters', 'city' => 'Boondock', 'state' => 'TN', 'something' => NULL)), array('Person' => array('first_name' => 'Garrett', 'last_name' => 'Woodworth', 'city' => 'Venice Beach', 'state' => 'CA', 'something' => NULL)));
     $result = Set::format($data, '%s', array('{n}.Person.something'));
     $expected = array('42', '', '');
     $this->assertEquals($expected, $result);
     $result = Set::format($data, '{0}, {1}', array('{n}.Person.city', '{n}.Person.something'));
     $expected = array('Boston, 42', 'Boondock, ', 'Venice Beach, ');
     $this->assertEquals($expected, $result);
 }
开发者ID:mrbadao,项目名称:api-official,代码行数:15,代码来源:SetTest.php

示例3: combine

 /**
  * Creates an associative array using a $path1 as the path to build its keys, and optionally
  * $path2 as path to get the values. If $path2 is not specified, all values will be initialized
  * to null (useful for Set::merge). You can optionally group the values by what is obtained when
  * following the path specified in $groupPath.
  *
  * @param array $data Array from where to extract keys and values
  * @param mixed $path1 As an array, or as a dot-separated string.
  * @param mixed $path2 As an array, or as a dot-separated string.
  * @param string $groupPath As an array, or as a dot-separated string.
  * @return array Combined array
  * @access public
  */
 function combine($data, $path1 = null, $path2 = null, $groupPath = null)
 {
     if (is_a($this, 'set') && is_string($data) && is_string($path1) && is_string($path2)) {
         $groupPath = $path2;
         $path2 = $path1;
         $path1 = $data;
         $data = $this->get();
     } elseif (is_a($this, 'set') && is_string($data) && empty($path2)) {
         $path2 = $path1;
         $path1 = $data;
         $data = $this->get();
     }
     if (is_object($data)) {
         $data = get_object_vars($data);
     }
     if (is_array($path1)) {
         $format = array_shift($path2);
         $keys = Set::format($data, $format, $path1);
     } else {
         $keys = Set::extract($data, $path1);
     }
     if (!empty($path2) && is_array($path2)) {
         $format = array_shift($path2);
         $vals = Set::format($data, $format, $path2);
     } elseif (!empty($path2)) {
         $vals = Set::extract($data, $path2);
     } else {
         $count = count($keys);
         for ($i = 0; $i < $count; $i++) {
             $vals[$i] = null;
         }
     }
     if ($groupPath != null) {
         $group = Set::extract($data, $groupPath);
         if (!empty($group)) {
             $c = count($keys);
             for ($i = 0; $i < $c; $i++) {
                 if (!isset($group[$i])) {
                     $group[$i] = 0;
                 }
                 if (!isset($out[$group[$i]])) {
                     $out[$group[$i]] = array();
                 }
                 $out[$group[$i]][$keys[$i]] = $vals[$i];
             }
             return $out;
         }
     }
     return array_combine($keys, $vals);
 }
开发者ID:sukhjeet81,项目名称:capuchn,代码行数:63,代码来源:set.php

示例4: combine

 /**
  * Creates an associative array using a $path1 as the path to build its keys, and optionally
  * $path2 as path to get the values. If $path2 is not specified, all values will be initialized
  * to null (useful for Set::merge). You can optionally group the values by what is obtained when
  * following the path specified in $groupPath.
  *
  * @param array|object $data Array or object from where to extract keys and values
  * @param string|array $path1 As an array, or as a dot-separated string.
  * @param string|array $path2 As an array, or as a dot-separated string.
  * @param string $groupPath As an array, or as a dot-separated string.
  * @return array Combined array
  * @link http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::combine
  */
 public static function combine($data, $path1 = null, $path2 = null, $groupPath = null)
 {
     if (empty($data)) {
         return array();
     }
     if (is_object($data)) {
         if (!($data instanceof ArrayAccess || $data instanceof Traversable)) {
             $data = get_object_vars($data);
         }
     }
     if (is_array($path1)) {
         $format = array_shift($path1);
         $keys = Set::format($data, $format, $path1);
     } else {
         $keys = Set::extract($data, $path1);
     }
     if (empty($keys)) {
         return array();
     }
     if (!empty($path2) && is_array($path2)) {
         $format = array_shift($path2);
         $vals = Set::format($data, $format, $path2);
     } elseif (!empty($path2)) {
         $vals = Set::extract($data, $path2);
     } else {
         $count = count($keys);
         for ($i = 0; $i < $count; $i++) {
             $vals[$i] = null;
         }
     }
     if ($groupPath != null) {
         $group = Set::extract($data, $groupPath);
         if (!empty($group)) {
             $c = count($keys);
             for ($i = 0; $i < $c; $i++) {
                 if (!isset($group[$i])) {
                     $group[$i] = 0;
                 }
                 if (!isset($out[$group[$i]])) {
                     $out[$group[$i]] = array();
                 }
                 $out[$group[$i]][$keys[$i]] = $vals[$i];
             }
             return $out;
         }
     }
     if (empty($vals)) {
         return array();
     }
     return array_combine($keys, $vals);
 }
开发者ID:aichelman,项目名称:StudyUp,代码行数:64,代码来源:Set.php

示例5: testFormatting

 /**
  * testFormatting method
  *
  * @access public
  * @return void
  */
 function testFormatting()
 {
     $data = array(array('Person' => array('first_name' => 'Nate', 'last_name' => 'Abele', 'city' => 'Boston', 'state' => 'MA', 'something' => '42')), array('Person' => array('first_name' => 'Larry', 'last_name' => 'Masters', 'city' => 'Boondock', 'state' => 'TN', 'something' => '{0}')), array('Person' => array('first_name' => 'Garrett', 'last_name' => 'Woodworth', 'city' => 'Venice Beach', 'state' => 'CA', 'something' => '{1}')));
     $result = Set::format($data, '{1}, {0}', array('{n}.Person.first_name', '{n}.Person.last_name'));
     $expected = array('Abele, Nate', 'Masters, Larry', 'Woodworth, Garrett');
     $this->assertEqual($result, $expected);
     $result = Set::format($data, '{0}, {1}', array('{n}.Person.last_name', '{n}.Person.first_name'));
     $this->assertEqual($result, $expected);
     $result = Set::format($data, '{0}, {1}', array('{n}.Person.city', '{n}.Person.state'));
     $expected = array('Boston, MA', 'Boondock, TN', 'Venice Beach, CA');
     $this->assertEqual($result, $expected);
     $result = Set::format($data, '{{0}, {1}}', array('{n}.Person.city', '{n}.Person.state'));
     $expected = array('{Boston, MA}', '{Boondock, TN}', '{Venice Beach, CA}');
     $this->assertEqual($result, $expected);
     $result = Set::format($data, '{{0}, {1}}', array('{n}.Person.something', '{n}.Person.something'));
     $expected = array('{42, 42}', '{{0}, {0}}', '{{1}, {1}}');
     $this->assertEqual($result, $expected);
     $result = Set::format($data, '{%2$d, %1$s}', array('{n}.Person.something', '{n}.Person.something'));
     $expected = array('{42, 42}', '{0, {0}}', '{0, {1}}');
     $this->assertEqual($result, $expected);
     $result = Set::format($data, '{%1$s, %1$s}', array('{n}.Person.something', '{n}.Person.something'));
     $expected = array('{42, 42}', '{{0}, {0}}', '{{1}, {1}}');
     $this->assertEqual($result, $expected);
     $result = Set::format($data, '%2$d, %1$s', array('{n}.Person.first_name', '{n}.Person.something'));
     $expected = array('42, Nate', '0, Larry', '0, Garrett');
     $this->assertEqual($result, $expected);
     $result = Set::format($data, '%1$s, %2$d', array('{n}.Person.first_name', '{n}.Person.something'));
     $expected = array('Nate, 42', 'Larry, 0', 'Garrett, 0');
     $this->assertEqual($result, $expected);
 }
开发者ID:subh,项目名称:raleigh-workshop-08,代码行数:36,代码来源:set.test.php


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