本文整理汇总了PHP中CHtml::value方法的典型用法代码示例。如果您正苦于以下问题:PHP CHtml::value方法的具体用法?PHP CHtml::value怎么用?PHP CHtml::value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CHtml
的用法示例。
在下文中一共展示了CHtml::value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRbamName
/**
* Returns the user's name.
* @return string the user's name.
*/
public function getRbamName() {
if ($this->_name===null) {
$owner = $this->getOwner();
$attribute = Yii::app()->findModule('rbam')->userNameAttribute;
if (is_string($attribute) && strpos($attribute, ',')!==false)
$attribute = explode(',', str_replace('\,',self::COMMA,$attribute));
if (is_array($attribute)) {
$glue = str_replace(self::COMMA,',',array_shift($attribute));
$end = end($attribute);
$initials = ((is_array($end) || strpos($end, self::COMMA)!==false || strpos($end, ',')!==false)?array_pop($attribute):array());
if (!empty($initials)) {
if (is_string($initials))
$initials = explode(',', str_replace('\,',self::COMMA,str_replace(self::COMMA,',',$initials)));
$append = str_replace(self::COMMA,',',array_shift($initials));
}
$attributes = array();
foreach ($attribute as $attr) {
$value = CHtml::value($owner,$attr);
if (!empty($value))
$attributes[] = (in_array($attr, $initials)?substr($value,0,1).$append:$value);
}
$this->_name = join($glue, $attributes);
}
else
$this->_name = $owner->$attribute;
}
return $this->_name;
}
示例2: actionView
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id = null, $path = null)
{
//if path is given, find the content_id from the menu item
if ($path) {
$Content = Content::model()->findByAttributes(array('path' => $path));
} else {
$Content = $this->loadModel($id);
}
$Content = $this->loadModel($id);
$MI = MenuItem::model()->findByAttributes(array('content_id' => $Content->id));
if (!Yii::app()->user->checkAccess('Update Content')) {
$today = new DateTime();
$publish_on = new DateTime($Content->publish_on);
$unpublish_on = new DateTime($Content->unpublish_on);
if (!$Content->published || $publish_on > $today || $unpublish_on < $today) {
throw new CHttpException(403, Yii::t('yii', 'You are not authorized to perform this action.'));
}
}
//$this->layout = '//layouts/column1';
$view = 'view';
if ($this->getLayoutFile('//layouts/content_types/' . $Content->type)) {
$this->layout = '//layouts/content_types/' . $Content->type;
}
if ($this->getViewFile($Content->type)) {
$view = $Content->type;
}
$this->meta_keywords = CHtml::value($Content, 'meta_keywords');
$this->meta_description = CHtml::value($Content, 'meta_description');
$this->meta_author = CHtml::value($Content, 'UserCreated.full_name');
//Used by the admin bar
$this->Content = $Content;
$this->render($view, array('Content' => $Content, 'MenuItem' => $MI));
}
示例3: renderTableRow
public function renderTableRow($row)
{
$data = $this->dataProvider->data[$row];
$value = CHtml::value($data, $this->rankKey);
$this->count++;
if ($this->lastRankValue != $value) {
$this->lastRankValue = $value;
$this->lastRank = $this->rank;
$this->rank = $this->count;
}
$htmlOptions = array();
if ($this->rowHtmlOptionsExpression !== null) {
$options = $this->evaluateExpression($this->rowHtmlOptionsExpression, array('row' => $row, 'data' => $data, 'rank' => $this->rank));
if (is_array($options)) {
$htmlOptions = $options;
}
}
if ($this->rowCssClassExpression !== null) {
$class = $this->evaluateExpression($this->rowCssClassExpression, array('row' => $row, 'data' => $data, 'rank' => $this->rank));
} elseif (is_array($this->rowCssClass) && ($n = count($this->rowCssClass)) > 0) {
$class = $this->rowCssClass[$row % $n];
}
if (!empty($class)) {
if (isset($htmlOptions['class'])) {
$htmlOptions['class'] .= ' ' . $class;
} else {
$htmlOptions['class'] = $class;
}
}
echo CHtml::openTag('tr', $htmlOptions) . "\n";
foreach ($this->columns as $column) {
$column->renderDataCell($row);
}
echo "</tr>\n";
}
示例4: renderTableRow
/**
* Renders a table body row.
* @param integer $row the row number (zero-based).
* Adds in data for drag & drop ordering if id and sort_order fields available.
*/
public function renderTableRow($row)
{
$data = $this->dataProvider->data[$row];
if (array_key_exists('Id', $data->tableSchema->columns)) {
$tag = '<tr data-record-id="' . CHtml::value($data, 'Id') . '"';
if (array_key_exists('sort_order', $data->tableSchema->columns)) {
$tag .= ' data-sort-order="' . CHtml::value($data, 'sort_order') . '"';
}
} else {
$tag = '<tr id="34444" ';
}
if ($this->rowCssClassExpression !== null) {
echo $tag .= ' class="' . $this->evaluateExpression($this->rowCssClassExpression, array('row' => $row, 'data' => $data)) . '">';
} else {
if (is_array($this->rowCssClass) && ($n = count($this->rowCssClass)) > 0) {
echo $tag .= ' class="' . $this->rowCssClass[$row % $n] . '">';
} else {
echo $tag .= '>';
}
}
foreach ($this->columns as $column) {
$column->renderDataCell($row);
}
echo "</tr>\n";
}
示例5: renderDataCellContent
/**
* Renders the data cell content.
* This method renders a checkbox in the data cell.
* @param integer $row the row number (zero-based)
* @param mixed $data the data associated with the row
* This method is Copyright (c) 2008-2014 by Yii Software LLC
* http://www.yiiframework.com/license/
*/
protected function renderDataCellContent($row, $data)
{
if ($this->value !== null) {
$value = $this->evaluateExpression($this->value, array('data' => $data, 'row' => $row));
} elseif ($this->name !== null) {
$value = CHtml::value($data, $this->name);
} else {
$value = $this->grid->dataProvider->keys[$row];
}
$checked = false;
if ($this->checked !== null) {
$checked = $this->evaluateExpression($this->checked, array('data' => $data, 'row' => $row));
}
$options = $this->checkBoxHtmlOptions;
if ($this->disabled !== null) {
$options['disabled'] = $this->evaluateExpression($this->disabled, array('data' => $data, 'row' => $row));
}
$name = $options['name'];
unset($options['name']);
$options['value'] = $value;
/* x2modstart */
// made id customizable through interface
if (isset($options['id'])) {
$options['id'] = $this->evaluateExpression($options['id'], array('data' => $data, 'row' => $row));
}
if (!isset($options['id'])) {
/* x2modend */
$options['id'] = $this->id . '_' . $row;
}
echo CHtml::checkBox($name, $checked, $options);
}
示例6: renderDataCellContent
public function renderDataCellContent($row, $data)
{
$isModel = $data instanceof CModel;
if ($isModel) {
$widgetClass = 'EditableField';
$attribute = empty($this->editable['attribute']) ? $this->name : $this->editable['attribute'];
$options = array('model' => $data, 'attribute' => $attribute);
//if value defined in column config --> we should evaluate it
//and pass to widget via `text` option: set flag `passText` = true
$passText = !empty($this->value);
} else {
$widgetClass = 'Editable';
$options = array('pk' => $data[$this->grid->dataProvider->keyField], 'name' => empty($this->editable['name']) ? $this->name : $this->editable['name']);
$passText = true;
//if autotext will be applied, do not pass `text` option (pass `value` instead)
if (empty($this->value) && Editable::isAutotext($this->editable, isset($this->editable['type']) ? $this->editable['type'] : '')) {
$options['value'] = $data[$this->name];
$passText = false;
}
}
//for live update
$options['liveTarget'] = $this->grid->id;
$options = CMap::mergeArray($this->editable, $options);
//get text for element
$ctext = CHtml::value($data, $attribute);
//if value defined for column --> use it as element text
if ($passText) {
ob_start();
parent::renderDataCellContent($row, $data);
$text = ob_get_clean();
$ctext = $text;
$options['text'] = $text;
$options['encode'] = false;
}
//apply may be a string expression, see https://github.com/vitalets/x-editable-yii/issues/33
if (isset($options['apply']) && is_string($options['apply'])) {
$options['apply'] = $this->evaluateExpression($options['apply'], array('data' => $data, 'row' => $row));
}
//evaluate htmlOptions inside editable config as they can depend on $data
//see https://github.com/vitalets/x-editable-yii/issues/40
if (isset($options['htmlOptions']) && is_array($options['htmlOptions'])) {
foreach ($options['htmlOptions'] as $k => $v) {
if (is_string($v) && (strpos($v, '$data') !== false || strpos($v, '$row') !== false)) {
$options['htmlOptions'][$k] = $this->evaluateExpression($v, array('data' => $data, 'row' => $row));
}
}
}
$this->grid->controller->widget($widgetClass, $options);
//Added to support creating models on the fly
//$ctext = CHtml::value($data, $attribute);
$mClass = empty($this->modelName) ? get_class($data) : $this->modelName;
if (empty($this->parentModel)) {
echo cHtml::openTag('input', array('type' => 'hidden', 'class' => "optvalinput{$attribute}", 'id' => "{$mClass}_{$row}_{$attribute}", 'name' => "{$mClass}[{$row}][{$attribute}]", 'value' => $ctext));
} else {
echo cHtml::openTag('input', array('type' => 'hidden', 'class' => "optvalinput{$attribute}", 'id' => "{$this->parentModel[1]}_{$this->parentModel[0]}_{$mClass}_{$row}_{$attribute}", 'name' => "{$this->parentModel[1]}[{$this->parentModel[0]}][{$mClass}][{$row}][{$attribute}]", 'value' => $ctext));
}
echo cHtml::closeTag('input');
}
示例7: renderDataCellContent
protected function renderDataCellContent($row, $data)
{
if ($this->value !== null) {
$value = $this->evaluateExpression($this->value, array('data' => $data, 'row' => $row, 'rank' => $this->grid->rank, 'lastRank' => $this->grid->lastRank, 'displayRank' => $this->grid->getDisplayRank($row)));
} elseif ($this->name !== null) {
$value = CHtml::value($data, $this->name);
}
echo $value === null ? $this->grid->nullDisplay : $this->grid->getFormatter()->format($value, $this->type);
}
示例8: getItemValue
protected function getItemValue($row, $data)
{
if (!empty($this->value)) {
return $this->evaluateExpression($this->value, array('data' => $data, 'row' => $row));
} elseif (!empty($this->name)) {
return CHtml::value($data, $this->name);
}
return null;
}
示例9: renderDataCellContent
protected function renderDataCellContent($row, $data)
{
$value = CHtml::value($data, $this->name);
$this->callbackUrl['pk'] = $data->primaryKey;
$this->callbackUrl['name'] = urlencode($this->name);
$this->callbackUrl['value'] = (int) empty($value);
$link = CHtml::normalizeUrl($this->callbackUrl);
echo CHtml::link(!empty($value) ? 'Y' : 'N', $link, array('class' => $this->_flagClass));
}
示例10: renderDataCellContent
/**
* Renders the data cell content.
* This method renders a hyperlink in the data cell.
* @param integer $row the row number (zero-based)
* @param mixed $data the data associated with the row
*/
protected function renderDataCellContent($row,$data)
{
echo CHtml::link(
CHtml::image(
CHtml::value($data,$this->name) ? $this->onButtonImageUrl : $this->offButtonImageUrl
),
Yii::app()->controller->createUrl(($this->action?$this->action:$this->name),array("id"=>$data->primaryKey)),
array('class'=>'onoffbutton')
);
}
示例11: run
public function run()
{
$formatter = $this->getFormatter();
echo CHtml::openTag($this->tagName, $this->htmlOptions);
$i = 0;
$n = is_array($this->itemCssClass) ? count($this->itemCssClass) : 0;
foreach ($this->attributes as $attribute) {
if (is_string($attribute)) {
if (!preg_match('/^([\\w\\.]+)(:(\\w*))?(:(.*))?$/', $attribute, $matches)) {
throw new CException(Yii::t('zii', 'The attribute must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.'));
}
$attribute = array('name' => $matches[1], 'type' => isset($matches[3]) ? $matches[3] : 'text');
if (isset($matches[5])) {
$attribute['label'] = $matches[5];
}
}
if (isset($attribute['visible']) && !$attribute['visible']) {
continue;
}
$tr = array('{label}' => '', '{class}' => $n ? $this->itemCssClass[$i % $n] : '');
if (isset($attribute['cssClass'])) {
$tr['{class}'] = $attribute['cssClass'] . ' ' . ($n ? $tr['{class}'] : '');
}
if (isset($attribute['label'])) {
$tr['{label}'] = $attribute['label'];
} else {
if (isset($attribute['name'])) {
if ($this->data instanceof CModel) {
$tr['{label}'] = $this->data->getAttributeLabel($attribute['name']);
} else {
$tr['{label}'] = ucwords(trim(strtolower(str_replace(array('-', '_', '.'), ' ', preg_replace('/(?<![A-Z])[A-Z]/', ' \\0', $attribute['name'])))));
}
}
}
if (!isset($attribute['type'])) {
$attribute['type'] = 'text';
}
if (isset($attribute['value'])) {
$value = $attribute['value'];
} else {
if (isset($attribute['name'])) {
$value = CHtml::value($this->data, $attribute['name']);
if (Yii::app()->dater->isDbDate($value)) {
$value = Yii::app()->dater->readableFormat($value);
}
} else {
$value = null;
}
}
$tr['{value}'] = $value === null ? $this->nullDisplay : $formatter->format($value, $attribute['type']);
echo strtr(isset($attribute['template']) ? $attribute['template'] : $this->itemTemplate, $tr);
$i++;
}
echo CHtml::closeTag($this->tagName);
}
示例12: renderDataCellContent
protected function renderDataCellContent($row, $data)
{
$value = CHtml::value($data, $this->name);
$this->callbackUrl['pk'] = $data->primaryKey;
$this->callbackUrl['name'] = urlencode($this->name);
$this->callbackUrl['value'] = (int) empty($value);
$link = CHtml::normalizeUrl($this->callbackUrl);
$yes = $this->icons ? CHtml::image($this->_assets . '/checkbox-checked.png') : '+';
$no = $this->icons ? CHtml::image($this->_assets . '/checkbox-unchecked.png') : '-';
echo CHtml::link(!empty($value) ? $yes : $no, $link, array('class' => $this->_flagClass));
}
示例13: renderDataCellContent
/**
* Renders the data cell content.
* This method evaluates {@link value} or {@link name} and renders the result.
*
* @param integer $row the row number (zero-based)
* @param mixed $data the data associated with the row
*/
protected function renderDataCellContent($row, $data)
{
$value = CHtml::value($data, $this->name);
$valueId = $data->{$this->modelId};
$this->htmlEditFieldOptions['itemId'] = $valueId;
$fieldUID = $this->getViewDivClass();
echo CHtml::tag('div', array('valueid' => $valueId, 'id' => $fieldUID . '-' . $valueId, 'class' => $fieldUID), $value);
echo CHtml::openTag('div', array('style' => 'display: none;', 'id' => $this->getFieldDivClass() . $data->{$this->modelId}));
echo CHtml::textField($this->name . '[' . $valueId . ']', $value, $this->htmlEditFieldOptions);
echo CHtml::closeTag('div');
}
示例14: renderDataCellContent
/**
* Renders the data cell content.
* This method evaluates {@link value} or {@link name} and renders the result.
* @param integer $row the row number (zero-based)
* @param mixed $data the data associated with the row
*/
protected function renderDataCellContent($row, $data)
{
if ($this->value !== null) {
$value = $this->evaluateExpression($this->value, array('data' => $data, 'row' => $row));
if (!empty($this->data) && isset($this->data[$value])) {
$value = $this->data[$value];
}
} elseif ($this->name !== null) {
$value = CHtml::value($data, $this->name);
}
echo $value === null ? $this->grid->nullDisplay : $this->grid->getFormatter()->format($value, $this->type);
}
示例15: renderDataCellContent
protected function renderDataCellContent($row, $data)
{
if ($this->format === null) {
$this->format = "dd.MM.yyyy HH:mm:ss";
}
$this->grid->getFormatter()->dateFormat = $this->format;
if ($this->value !== null) {
$value = $this->evaluateExpression($this->value, array('data' => $data, 'row' => $row));
} elseif ($this->name !== null) {
$value = CHtml::value($data, $this->name);
}
echo $value === null ? $this->grid->nullDisplay : Yii::app()->dateFormatter->format($this->format, $value);
}