本文整理汇总了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;
}