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


PHP CComponent::evaluateExpression方法代码示例

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


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

示例1: getRelatedData

 /**
  * This function fetches all needed data of the related Object and returns them
  * in an array that is prepared for use in ListData.
  */
 public function getRelatedData()
 {
     /* At first we determine, if we want to display all parent Objects, or
      * if the User supplied an list of Objects */
     if (is_object($this->parentObjects)) {
         $parentobjects = array($this->parentObjects);
     } else {
         if (is_array($this->parentObjects)) {
             $parentobjects = $this->parentObjects;
         } else {
             $parentobjects = CActiveRecord::model(get_class($this->_relatedModel))->findAll();
         }
     }
     if ($this->allowEmpty) {
         if (is_string($this->allowEmpty)) {
             $dataArray[0] = $this->allowEmpty;
         } else {
             $dataArray[0] = Yii::t('app', 'None');
         }
     }
     foreach ($parentobjects as $obj) {
         if (!is_array($this->fields)) {
             $this->fields = array($this->fields);
         }
         $fields = '';
         foreach ($this->fields as $field) {
             $rule = sprintf('{%s}', $field);
             $rules[$rule] = $obj->{$field};
             $fields .= $this->getModelData($obj, $field);
             if (count($this->fields) > 1) {
                 $fields .= $this->delimiter;
             }
         }
         $defaultrules = array('{fields}' => $fields, '{id}' => $obj->id);
         // Look for user-contributed functions and evaluate them
         if ($this->functions != array()) {
             foreach ($this->functions as $key => $function) {
                 $funcrules[sprintf('{func%d}', $key)] = CComponent::evaluateExpression(strtr($function, $defaultrules));
             }
         }
         // Merge the evaluated rules, if exist
         if (isset($funcrules)) {
             $rules = array_merge($rules, $funcrules);
         }
         // Merge the default rules into our ruleset
         $rules = array_merge($rules, $defaultrules);
         // Apply the rules to the template
         $value = strtr($this->template, $rules);
         if ($this->groupParentsBy != '') {
             $dataArray[$obj->{$this->groupParentsBy}][$obj->{$this->relatedPk}] = $value;
         } else {
             $dataArray[$obj->{$this->relatedPk}] = $value;
         }
     }
     if (!isset($dataArray) || !is_array($dataArray)) {
         $dataArray = array();
     }
     return $dataArray;
 }
开发者ID:engrasadullahkhan,项目名称:stockcontrolweb,代码行数:63,代码来源:Relation.php


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