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


PHP TableRegistry::associationLabels方法代码示例

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


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

示例1: _getTabLabels

 /**
  * _getTabLabels
  *
  * Re-arrange tabs naming based on the config.ini and fieldNames
  * to avoid repetitive namings
  * @param Cake\ORM\TableRegistry $tableInstance passed
  * @param array $config of the config.ini
  *
  * @return array $labels with key/value storage of alias/name
  */
 protected function _getTabLabels($tableInstance, $config = [])
 {
     $labels = [];
     $associationLabels = [];
     if (!empty($config['associationLabels'])) {
         $associationLabels = $tableInstance->associationLabels($config['associationLabels']);
     }
     $labelCounts = [];
     // Gather labels for all associations
     foreach ($tableInstance->associations() as $association) {
         $assocTableInstance = TableRegistry::get($association->table());
         $icon = $this->_getTableIcon($assocTableInstance);
         $assocAlias = $association->alias();
         // Initialize association label array with the icon
         if (empty($labels[$assocAlias])) {
             $labels[$assocAlias] = ['icon' => $icon];
         }
         if (in_array($assocAlias, array_keys($associationLabels))) {
             // If label exists in config.ini, use it.
             $labels[$assocAlias]['label'] = $associationLabels[$assocAlias];
         } else {
             // Otherwise use table alias or name as label
             $labels[$assocAlias]['label'] = Inflector::humanize($association->table());
             if (method_exists($assocTableInstance, 'moduleAlias')) {
                 $labels[$assocAlias]['label'] = Inflector::humanize($assocTableInstance->moduleAlias());
             }
         }
         // Initialize counter for current label, if needed
         if (empty($labelCounts[$labels[$assocAlias]['label']])) {
             $labelCounts[$labels[$assocAlias]['label']] = 0;
         }
         // Bump up label counter
         $labelCounts[$labels[$assocAlias]['label']]++;
     }
     // Not that we have all the labels, check if we have any duplicate labels
     // and append the association field name to those that are not unique.
     // Also, while we are at it, construct the actual label string from the
     // icon, label, and field name.
     foreach ($labels as $assocAlias => $label) {
         $labels[$assocAlias] = $label['icon'] . $label['label'];
         if ($labelCounts[$label['label']] <= 1) {
             // If the label is unique, we have nothing else to do
             continue;
         }
         // Get the association field and clean it up, removing the association name
         // from the field.  So, for 'primaryContactIdLeads', we'll do the following:
         // * Tableize: primary_contact_id_leads
         // * Humanize: Primary Contact Id Leads
         // * Remove association table: Primary Contact Id
         $fieldName = Inflector::humanize(Inflector::tableize($assocAlias));
         $fieldName = str_replace($assocAlias, '', Inflector::humanize(Inflector::tableize($assocAlias)));
         $fieldName = trim(str_replace($label['label'], '', $fieldName));
         // Field can be empty in case of, for example, many-to-many relationships.
         if (!empty($fieldName)) {
             $labels[$assocAlias] .= sprintf(" (%s)", $fieldName);
         }
     }
     return $labels;
 }
开发者ID:QoboLtd,项目名称:cakephp-csv-migrations,代码行数:69,代码来源:ViewViewTabsListener.php


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