Inflector::underscore PHP Method

underscore() public static method

public static underscore ( $string )
    public static function underscore($string)
    {
        return strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $string));
    }

Usage Example

Esempio n. 1
0
 public static function getExternalConditions($select, $parentModel, $childName, $attributes)
 {
     $parentModelName = get_class($parentModel);
     $parentTableName = $parentModel->getTableName();
     // exhibitions
     $childName = array_key_exists('source', $attributes) ? $attributes['source'] : $childName;
     $childModelName = Inflector::classify($childName);
     $childTableName = Bbx_Model::load($childModelName)->getTableName();
     // images
     if (!array_key_exists($childTableName, $select->getPart('from'))) {
         $select->from($childTableName, array());
         // images
     }
     if (array_key_exists('as', $attributes)) {
         $refColumn = $attributes['as'] . '_id';
         $polyType = $attributes['as'] . '_type';
     } else {
         $refColumn = Inflector::singularize($parentTableName) . '_id';
     }
     try {
         $parentModel->getRowData();
         $select->where("`" . $childTableName . "`.`" . $refColumn . "` = " . $parentModel->id);
     } catch (Exception $e) {
         $select->where("`" . $childTableName . "`.`" . $refColumn . "` = `" . $parentTableName . "`.`id`");
     }
     if (isset($polyType)) {
         $select->where("`" . $childTableName . "`.`" . $polyType . "` = '" . Inflector::underscore($parentModelName) . "'");
     }
     return $select;
 }
All Usage Examples Of Inflector::underscore