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


PHP fHTML::makeLinks方法代码示例

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


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

示例1: prepare

 /**
  * Retrieves a value from the record and prepares it for output into html.
  * 
  * Below are the transformations performed:
  * 
  *  - **varchar, char, text**: will run through fHTML::prepare(), if `TRUE` is passed the text will be run through fHTML::convertNewLinks() and fHTML::makeLinks()
  *  - **boolean**: will return `'Yes'` or `'No'`
  *  - **integer**: will add thousands/millions/etc. separators
  *  - **float**: will add thousands/millions/etc. separators and takes 1 parameter to specify the number of decimal places
  *  - **date, time, timestamp**: `format()` will be called on the fDate/fTime/fTimestamp object with the 1 parameter specified
  *  - **objects**: the object will be converted to a string by `__toString()` or a `(string)` cast and then will be run through fHTML::prepare()
  * 
  * @param  string $column      The name of the column to retrieve
  * @param  mixed  $formatting  The formatting parameter, if applicable
  * @return string  The formatted value for the column specified
  */
 protected function prepare($column, $formatting = NULL)
 {
     $column_exists = array_key_exists($column, $this->values);
     $method_name = 'get' . fGrammar::camelize($column, TRUE);
     $method_exists = method_exists($this, $method_name);
     if (!$column_exists && !$method_exists) {
         throw new fProgrammerException('The column specified, %s, does not exist', $column);
     }
     if ($column_exists) {
         $class = get_class($this);
         $table = fORM::tablize($class);
         $schema = fORMSchema::retrieve($class);
         $column_info = $schema->getColumnInfo($table, $column);
         $column_type = $column_info['type'];
         // Ensure the programmer is calling the function properly
         if ($column_type == 'blob') {
             throw new fProgrammerException('The column specified, %s, can not be prepared because it is a blob column', $column);
         }
         if ($formatting !== NULL && in_array($column_type, array('integer', 'boolean'))) {
             throw new fProgrammerException('The column specified, %s, does not support any formatting options', $column);
         }
         // If the column doesn't exist, we are just pulling the
         // value from a get method, so treat it as text
     } else {
         $column_type = 'text';
     }
     // Grab the value for empty value checking
     $value = $this->{$method_name}();
     // Date/time objects
     if (is_object($value) && in_array($column_type, array('date', 'time', 'timestamp'))) {
         if ($formatting === NULL) {
             throw new fProgrammerException('The column specified, %s, requires one formatting parameter, a valid date() formatting string', $column);
         }
         return $value->format($formatting);
     }
     // Other objects
     if (is_object($value) && is_callable(array($value, '__toString'))) {
         $value = $value->__toString();
     } elseif (is_object($value)) {
         $value = (string) $value;
     }
     // Ensure the value matches the data type specified to prevent mangling
     if ($column_type == 'boolean' && is_bool($value)) {
         return $value ? 'Yes' : 'No';
     }
     if ($column_type == 'integer' && is_numeric($value)) {
         return number_format($value, 0, '', ',');
     }
     if ($column_type == 'float' && is_numeric($value)) {
         // If the user passed in a formatting value, use it
         if ($formatting !== NULL && is_numeric($formatting)) {
             $decimal_places = (int) $formatting;
             // If the column has a pre-defined number of decimal places, use that
         } elseif ($column_info['decimal_places'] !== NULL) {
             $decimal_places = $column_info['decimal_places'];
             // This figures out how many decimal places are part of the current value
         } else {
             $value_parts = explode('.', $value);
             $decimal_places = !isset($value_parts[1]) ? 0 : strlen($value_parts[1]);
         }
         return number_format($value, $decimal_places, '.', ',');
     }
     // Turn line-breaks into breaks for text fields and add links
     if ($formatting === TRUE && in_array($column_type, array('varchar', 'char', 'text'))) {
         return fHTML::makeLinks(fHTML::convertNewlines(fHTML::prepare($value)));
     }
     // Anything that has gotten to here is a string value, or is not the
     // proper data type for the column, so we just make sure it is marked
     // up properly for display in HTML
     return fHTML::prepare($value);
 }
开发者ID:mrjwc,项目名称:printmaster,代码行数:87,代码来源:fActiveRecord.php

示例2: testMakeLinks

 /**
  * @dataProvider makeLinksProvider
  */
 public function testMakeLinks($input, $length, $output)
 {
     $this->assertEquals($output, fHTML::makeLinks($input, $length));
 }
开发者ID:nurulimamnotes,项目名称:flourish-old,代码行数:7,代码来源:fHTMLTest.php


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