本文整理汇总了PHP中yii\helpers\Html::getAttributeValue方法的典型用法代码示例。如果您正苦于以下问题:PHP Html::getAttributeValue方法的具体用法?PHP Html::getAttributeValue怎么用?PHP Html::getAttributeValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Html
的用法示例。
在下文中一共展示了Html::getAttributeValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderSavedValueInput
public function renderSavedValueInput()
{
if ($this->hasModel()) {
$value = Html::getAttributeValue($this->model, $this->attribute);
} else {
$value = $this->value;
}
if ($value !== null && $value !== '') {
// format value according to saveDateFormat
try {
$value = Yii::$app->formatter->asDate($value, $this->saveDateFormat);
} catch (InvalidParamException $e) {
// ignore exception and keep original value if it is not a valid date
}
}
$this->options['savedValueInputID'] = $this->options['id'] . '-saved-value';
$options = $this->options;
$options['id'] = $options['savedValueInputID'];
$options['value'] = $value;
// render hidden input
if ($this->hasModel()) {
$contents = Html::activeHiddenInput($this->model, $this->attribute, $options);
} else {
$contents = Html::hiddenInput($this->name, $value, $options);
}
return $contents;
}
示例2: run
/**
* @inheritdoc
*/
public function run()
{
$inputId = $this->options['id'];
$hasModel = $this->hasModel();
if (array_key_exists('value', $this->options)) {
$value = $this->options['value'];
} elseif ($hasModel) {
$value = Html::getAttributeValue($this->model, $this->attribute);
} else {
$value = $this->value;
}
$options = array_merge($this->options, ['multiple' => true, 'value' => $value]);
if ($hasModel) {
$output = Html::activeListBox($this->model, $this->attribute, $this->items, $options);
} else {
$output = Html::listBox($this->name, $this->value, $this->items, $options);
}
$clientOptions = array_merge(['filter' => $this->filter, 'multiple' => $this->multiple, 'multipleWidth' => $this->multipleWidth], $this->clientOptions);
if (!array_key_exists('placeholder', $clientOptions) && array_key_exists('placeholder', $options)) {
$clientOptions['placeholder'] = $options['placeholder'];
}
$js = 'jQuery(\'#' . $inputId . '\').multipleSelect(' . Json::htmlEncode($clientOptions) . ');';
if (Yii::$app->getRequest()->getIsAjax()) {
$output .= Html::script($js);
} else {
$view = $this->getView();
MultipleSelectAsset::register($view);
$view->registerJs($js);
}
return $output;
}
示例3: run
/**
* @inheritdoc
*/
public function run()
{
try {
$this->_initAndValidate();
$valueArray = [];
$trees = [];
$valueSingle = "";
$select = "";
$singleInput = "";
if (in_array($this->mode, [self::MOD_COMBO, self::MOD_MULTI])) {
$valueArray = Html::getAttributeValue($this->model, $this->attribute);
$select = Html::activeListBox($this->model, $this->attribute, ['16' => "16"], ['multiple' => true, 'class' => 'sx-controll-element', 'style' => 'display: none;']);
$trees = Tree::find()->where(['id' => $valueArray])->all();
}
if (in_array($this->mode, [self::MOD_COMBO, self::MOD_SINGLE])) {
$singleInput = Html::activeInput("hidden", $this->model, $this->attributeSingle, ['class' => 'sx-single']);
$valueSingle = Html::getAttributeValue($this->model, $this->attributeSingle);
}
$src = UrlHelper::construct('/cms/admin-tree')->set('mode', $this->mode)->set('s', $valueArray)->setSystemParam(Module::SYSTEM_QUERY_EMPTY_LAYOUT, 'true')->setSystemParam(Module::SYSTEM_QUERY_NO_ACTIONS_MODEL, 'true')->enableAdmin()->toString();
$id = "sx-id-" . md5(serialize([$this->clientOptions, $this->mode, $this->attributeMulti, $this->attributeSingle]));
$selected = [];
foreach ($trees as $tree) {
$selected[] = $tree->id;
}
return $this->render('widget', ['widget' => $this, 'id' => $id, 'select' => $select, 'src' => $src, 'valueSingle' => $valueSingle, 'singleInput' => $singleInput, 'clientOptions' => Json::encode(['src' => $src, 'name' => $id, 'id' => $id, 'selected' => $selected, 'valueSingle' => $valueSingle])]);
//$this->registerClientScript();
} catch (Exception $e) {
echo $e->getMessage();
}
}
示例4: init
/**
* Initializes the widget.
* @throws \yii\base\InvalidConfigException
*/
public function init()
{
parent::init();
foreach ($this->items as $value => $item) {
if (is_string($item)) {
throw new InvalidConfigException("Items cannot be of type string.");
}
$item['options'] = ['value' => $value];
}
if ($this->hasModel()) {
$value = Html::getAttributeValue($this->model, $this->attribute);
if (!empty($value)) {
$defaultText = $value;
}
} else {
if (!empty($this->value)) {
$defaultText = $this->value;
}
}
if (empty($defaultText)) {
$defaultText = Yii::t('dosamigos/semantic/selection', 'Select...');
}
$this->defaultText = $this->encodeDefaultText ? Html::encode($defaultText) : $defaultText;
Html::addCssClass($this->options, 'selection');
}
示例5: init
public function init()
{
parent::init();
$this->_inputStr = '<div class="form-group">';
if ($this->hasModel()) {
$this->_inputStr .= Html::activeLabel($this->model, $this->attribute);
} else {
$this->_inputStr .= Html::label($this->name);
}
$this->_inputStr .= '<div id="' . Html::encode($this->name) . '" class="input-group date">';
if ($this->hasModel()) {
$value = Html::getAttributeValue($this->model, $this->attribute);
} else {
$value = $this->value;
}
if ($value !== null) {
$value = Yii::$app->formatter->asDatetime($value);
}
$options = $this->options;
$options['class'] = 'form-control';
//$options['readonly'] = '';
$options['value'] = $value;
if ($this->hasModel()) {
$this->_inputStr .= Html::activeTextInput($this->model, $this->attribute, $options);
} else {
$this->_inputStr .= Html::textInput($this->name, $this->value, $options);
}
$this->_inputStr .= '<span class="input-group-addon">
<span class="glyphicon-calendar glyphicon"></span>
</span>
</div>
</div>
';
}
示例6: init
/**
* @throws \yii\base\InvalidConfigException
*/
public function init()
{
parent::init();
$this->registerMessages();
if ($this->maxNumberOfFiles > 1) {
$this->multiple = true;
}
if ($this->hasModel()) {
$this->name = $this->name ?: Html::getInputName($this->model, $this->attribute);
$this->value = $this->value ?: Html::getAttributeValue($this->model, $this->attribute);
}
if (!array_key_exists('name', $this->clientOptions)) {
$this->clientOptions['name'] = $this->name;
}
if ($this->multiple && $this->value && !is_array($this->value)) {
throw new InvalidParamException('In "multiple" mode, value must be an array.');
}
if (!array_key_exists('fileparam', $this->url)) {
$this->url['fileparam'] = $this->getFileInputName();
}
if (!$this->files && $this->value) {
$this->files = $this->multiple ? $this->value : [$this->value];
}
$this->clientOptions = ArrayHelper::merge(['url' => Url::to($this->url), 'multiple' => $this->multiple, 'sortable' => $this->sortable, 'maxNumberOfFiles' => $this->maxNumberOfFiles, 'maxFileSize' => $this->maxFileSize, 'minFileSize' => $this->minFileSize, 'acceptFileTypes' => $this->acceptFileTypes, 'files' => $this->files, 'messages' => ['maxNumberOfFiles' => Yii::t($this->messagesCategory, 'Maximum number of files exceeded', [], 'en'), 'acceptFileTypes' => Yii::t($this->messagesCategory, 'File type not allowed', [], 'en'), 'maxFileSize' => Yii::t($this->messagesCategory, 'File is too large', [], 'en'), 'minFileSize' => Yii::t($this->messagesCategory, 'File is too small', [], 'en')]], $this->clientOptions);
}
示例7: run
/**
* @inheritdoc
*/
public function run()
{
$this->_msgCat = 'kvcolor';
if (!isset($this->type)) {
$this->type = $this->useNative ? 'color' : 'text';
}
$this->width = '60px';
$this->initI18N(__DIR__);
if (empty($this->html5Container['id'])) {
$this->html5Container['id'] = $this->options['id'] . '-cont';
}
if ($this->type === 'text') {
Html::addCssStyle($this->html5Options, 'display:none');
if ($this->pluginLoading) {
Html::addCssClass($this->html5Container, 'kv-center-loading');
}
}
$this->html5Options['value'] = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
if (substr($this->language, 0, 2) !== 'en') {
$this->_defaultOptions += ['cancelText' => Yii::t('kvcolor', 'cancel'), 'chooseText' => Yii::t('kvcolor', 'choose'), 'clearText' => Yii::t('kvcolor', 'Clear Color Selection'), 'noColorSelectedText' => Yii::t('kvcolor', 'No Color Selected'), 'togglePaletteMoreText' => Yii::t('kvcolor', 'more'), 'togglePaletteLessText' => Yii::t('kvcolor', 'less')];
}
Html::addCssClass($this->containerOptions, 'spectrum-group');
Html::addCssClass($this->html5Options, 'spectrum-source');
Html::addCssClass($this->options, 'spectrum-input');
if (!$this->useNative) {
Html::addCssClass($this->html5Container, 'input-group-sp');
$this->pluginOptions = array_replace_recursive($this->_defaultOptions, $this->pluginOptions);
}
$this->initInput();
$this->registerColorInput();
}
示例8: run
/**
* @inheritdoc
*/
public function run()
{
$inputId = $this->options['id'];
$hasModel = $this->hasModel();
if (array_key_exists('value', $this->options)) {
$value = $this->options['value'];
} elseif ($hasModel) {
$value = Html::getAttributeValue($this->model, $this->attribute);
} else {
$value = $this->value;
}
$options = array_merge($this->options, ['value' => $value]);
if ($hasModel) {
$output = Html::activeTextInput($this->model, $this->attribute, $options);
} else {
$output = Html::textInput($this->name, $this->value, $options);
}
if (!is_null($this->alias)) {
$clientOptions = array_merge($this->clientOptions, ['alias' => $this->alias]);
} else {
$clientOptions = array_merge($this->clientOptions, ['mask' => $this->mask]);
}
if (!array_key_exists('placeholder', $clientOptions) && array_key_exists('placeholder', $options)) {
$clientOptions['placeholder'] = $options['placeholder'];
}
$js = 'jQuery(\'#' . $inputId . '\').inputmask(' . Json::htmlEncode($clientOptions) . ');';
if (Yii::$app->getRequest()->getIsAjax()) {
$output .= Html::script($js);
} else {
$view = $this->getView();
InputMaskAsset::register($view);
$view->registerJs($js);
}
return $output;
}
示例9: run
public function run()
{
if (!$this->hasModel() || !$this->attribute) {
throw new InvalidConfigException('Fuzzydate DatePicker must have model and attribute.');
}
$view = $this->getView();
$asset = new DatePickerAsset();
$asset->register($view);
$view->registerJs("fuzzyReg();");
$id = Html::getInputId($this->model, $this->attribute);
$val = Html::getAttributeValue($this->model, $this->attribute);
if ($val && is_array($val)) {
$y = $val['y'];
if ($y) {
$m = $val['m'];
if (!$m) {
$m = 'null';
}
$d = $val['d'];
if (!$d) {
$d = 'null';
}
// Call this after initializing jQuery-objects
$view->registerJs("fuzzySet('{$id}', {$y}, {$m}, {$d});", View::POS_LOAD);
}
}
if (!$this->minYear) {
$this->minYear = date('Y');
}
if (!$this->maxYear) {
$this->maxYear = date('Y');
}
$widget = $this->getViewPath() . DIRECTORY_SEPARATOR . 'datePicker.php';
echo $view->renderFile($widget, ['widget' => $this]);
}
示例10: init
/**
* @throws \yii\base\InvalidConfigException
*/
public function init()
{
parent::init();
$this->registerMessages();
if ($this->maxNumberOfFiles > 1 || $this->multiple) {
$this->multiple = true;
}
if ($this->hasModel()) {
$this->name = $this->name ?: Html::getInputName($this->model, $this->attribute);
$this->value = $this->value ?: Html::getAttributeValue($this->model, $this->attribute);
}
if (!array_key_exists('name', $this->clientOptions)) {
$this->clientOptions['name'] = $this->name;
}
if ($this->multiple && $this->value && !is_array($this->value)) {
throw new InvalidParamException('In "multiple" mode, value must be an array.');
}
if (!array_key_exists('fileparam', $this->url)) {
$this->url['fileparam'] = $this->getFileInputName();
}
if (!$this->files && $this->value) {
$this->files = $this->multiple ? $this->value : [$this->value];
}
if ($this->files) {
foreach ($this->files as &$file) {
if (!isset($file['alias_url']) && is_array($file)) {
$option = isset($this->clientOptions['baseUrlAttribute']) ? $this->clientOptions['baseUrlAttribute'] : null;
$file['alias_url'] = $option ? isset($file[$option]) ? Yii::getAlias($file[$option]) : null : null;
}
}
}
$this->clientOptions = ArrayHelper::merge(['url' => Url::to($this->url), 'multiple' => $this->multiple, 'sortable' => $this->sortable, 'maxNumberOfFiles' => $this->maxNumberOfFiles, 'maxFileSize' => $this->maxFileSize, 'minFileSize' => $this->minFileSize, 'acceptFileTypes' => $this->acceptFileTypes, 'files' => $this->files, 'showPreviewFilename' => $this->showPreviewFilename, 'pathAttribute' => 'path', 'baseUrlAttribute' => 'base_url', 'pathAttributeName' => 'path', 'baseUrlAttributeName' => 'base_url', 'messages' => ['maxNumberOfFiles' => Yii::t($this->messagesCategory, 'Maximum number of files exceeded'), 'acceptFileTypes' => Yii::t($this->messagesCategory, 'File type not allowed'), 'maxFileSize' => Yii::t($this->messagesCategory, 'File is too large'), 'minFileSize' => Yii::t($this->messagesCategory, 'File is too small')]], $this->clientOptions);
}
示例11: run
/**
* @inheritdoc
*/
public function run()
{
$this->clientOptions = array_merge_recursive(self::$defaultSettings, $this->clientOptions);
$this->clientOptions['extended_valid_elements'] = implode(',', $this->clientOptions['extended_valid_elements']);
if ($this->hasModel()) {
$this->options['name'] = isset($this->options['name']) ? $this->options['name'] : Html::getInputName($this->model, $this->attribute);
if (isset($this->options['value'])) {
$value = $this->options['value'];
unset($this->options['value']);
} else {
$value = Html::getAttributeValue($this->model, $this->attribute);
}
if (!array_key_exists('id', $this->options)) {
$this->options['id'] = Html::getInputId($this->model, $this->attribute);
}
} else {
$options['name'] = $this->name;
$value = $this->value;
}
if (!isset($this->options['class'])) {
$this->options['class'] = 'tinymce';
}
echo Html::tag('div', $value, $this->options);
$this->registerClientScript();
}
示例12: composeFilterState
/**
* @param $column
* @return void
*/
public function composeFilterState($column)
{
if (!preg_match('/(^|.*\\])([\\w\\.]+)(\\[.*|$)/', $column->attribute, $matches)) {
throw new InvalidParamException('Attribute name must contain word characters only.');
}
$formName = $this->_gridView->filterModel->formName();
$value = Html::getAttributeValue($this->_gridView->filterModel, $column->attribute);
$keys = [$formName];
if ($matches[1] === '') {
$keys[] = $matches[2];
if ($matches[3] !== '') {
$keys[] = $matches[3];
}
} else {
$keys[] = $matches[1];
$keys[] = $matches[2];
if ($matches[3] !== '') {
$keys[] = $matches[3];
}
}
$s =& $this->_state;
foreach ($keys as $key) {
if (end($keys) === $key) {
is_array($s) and $s[$key] = $value;
} else {
$s[$key] = isset($s[$key]) ? $s[$key] : [];
$s =& $s[$key];
}
}
}
示例13: run
public function run()
{
call_user_func([$this, 'register' . ucfirst($this->driver) . 'ClientJs']);
$value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
// 已经传过图片,显示预览图
$image = $value ? Html::img(strpos($value, 'http:') === false ? \Yii::getAlias('@static') . '/' . $value : $value, ['width' => $this->options['previewWidth'], 'height' => $this->options['previewHeight']]) : '';
return $this->render('main', ['boxId' => $this->options['boxId'], 'hiddenInput' => $this->hiddenInput, 'image' => $image]);
}
示例14: run
/**
* @inheritdoc
*/
public function run()
{
$web = rtrim(\Yii::getAlias('@static'), '/');
$value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
$image = $value ? Html::img(strpos($value, 'http:') === false ? \Yii::getAlias('@static') . '/' . $value : $value, ['width' => $this->options['previewWidth'], 'height' => $this->options['previewHeight']]) : '';
$this->registerClientScript();
return $this->render('cropper', ['options' => $this->options, 'image' => $image, 'server' => $this->server, 'hiddenInput' => $this->hiddenInput, 'web' => $web]);
}
示例15: run
public function run()
{
$this->tagOptions['data-input'] = '#' . $this->options['id'];
$this->options['style'] = 'display: none;';
$this->registerClientScripts();
echo Html::tag('div', Html::getAttributeValue($this->model, $this->attribute), $this->tagOptions);
echo Html::activeTextarea($this->model, $this->attribute, $this->options);
}