本文整理汇总了PHP中yii\helpers\Json::htmlEncode方法的典型用法代码示例。如果您正苦于以下问题:PHP Json::htmlEncode方法的具体用法?PHP Json::htmlEncode怎么用?PHP Json::htmlEncode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Json
的用法示例。
在下文中一共展示了Json::htmlEncode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: defaultColumns
public static function defaultColumns()
{
return ['fqdn' => ['attribute' => 'fqdn', 'value' => function ($model) {
return $model->fqdn;
}], 'type' => ['value' => function ($model) {
return strtoupper($model->type);
}], 'value' => ['value' => function ($model) {
return $model->getValueText();
}], 'zone' => ['class' => MainColumn::className(), 'label' => Yii::t('hipanel:dns', 'Zone'), 'attribute' => 'name'], 'actions' => ['class' => ActionColumn::className(), 'template' => '{update} {delete}', 'visibleButtonsCount' => 2, 'options' => ['style' => 'width: 15%'], 'buttons' => ['update' => function ($url, $model, $key) {
if ($model->is_system) {
return Html::tag('div', Html::a('<i class="fa fa-pencil"></i> ' . Yii::t('hipanel', 'Update'), null, ['class' => 'btn btn-default btn-xs disabled']), ['data-placement' => 'top', 'data-toggle' => 'tooltip', 'title' => Yii::t('hipanel:dns', 'This record was created by hosting panel automatically and cannot be updated'), 'style' => 'display: inline-block; cursor: not-allowed;']);
}
$data = Html::a('<i class="fa fa-pencil"></i> ' . Yii::t('hipanel', 'Update'), null, ['class' => 'btn btn-default btn-xs edit-dns-toggle', 'data' => ['record_id' => $model->id, 'hdomain_id' => $model->hdomain_id, 'load-url' => Url::to(['@dns/record/update', 'hdomain_id' => $model->hdomain_id, 'id' => $model->id])]]);
$progress = Json::htmlEncode("<tr><td colspan='5'>" . Progress::widget(['id' => 'progress-bar', 'percent' => 100, 'barOptions' => ['class' => 'active progress-bar-striped', 'style' => 'width: 100%']]) . '</td></tr>');
Yii::$app->view->registerJs("\n \$('.edit-dns-toggle').click(function () {\n var record_id = \$(this).data('id');\n var hdomain_id = \$(this).data('hdomain_id');\n\n var currentRow = \$(this).closest('tr');\n var newRow = \$({$progress});\n\n \$(newRow).data({'record_id': record_id, hdomain_id: hdomain_id});\n \$('tr').filter(function () { return \$(this).data('id') == record_id; }).find('.btn-cancel').click();\n \$(newRow).insertAfter(currentRow);\n\n jQuery.ajax({\n url: \$(this).data('load-url'),\n type: 'GET',\n timeout: 0,\n error: function() {\n\n },\n success: function(data) {\n newRow.find('td').html(data);\n newRow.find('.btn-cancel').on('click', function (event) {\n event.preventDefault();\n newRow.remove();\n });\n }\n });\n\n });\n ");
return $data;
}, 'delete' => function ($url, $model, $key) {
if ($model->type === 'ns' && $model->is_system) {
return Html::tag('div', Html::a('<i class="fa text-danger fa-trash-o"></i> ' . Yii::t('hipanel', 'Delete'), null, ['class' => 'btn btn-default btn-xs disabled']), ['data-placement' => 'top', 'data-toggle' => 'tooltip', 'title' => Yii::t('hipanel:dns', 'This record is important for the domain zone viability and can not be deleted'), 'style' => 'display: inline-block; cursor: not-allowed;']);
}
return ModalButton::widget(['model' => $model, 'scenario' => 'delete', 'submit' => ModalButton::SUBMIT_PJAX, 'form' => ['action' => Url::to('@dns/record/delete')], 'button' => ['class' => 'btn btn-default btn-xs', 'label' => '<i class="fa text-danger fa-trash-o"></i> ' . Yii::t('hipanel', 'Delete')], 'modal' => ['header' => Html::tag('h4', Yii::t('hipanel:dns', 'Confirm DNS record deleting')), 'headerOptions' => ['class' => 'label-danger'], 'footer' => ['label' => Yii::t('hipanel:dns', 'Delete record'), 'data-loading-text' => Yii::t('hipanel:dns', 'Deleting record...'), 'class' => 'btn btn-danger']], 'body' => function ($model) {
echo Html::activeHiddenInput($model, 'hdomain_id');
echo Yii::t('hipanel:dns', 'Are you sure, that you want to delete record {name}?', ['name' => $model->fqdn]);
}]);
}]]];
}
示例3: run
/**
* @inheritdoc
*/
public function run()
{
Asset::register($this->view);
$inputId = Html::getInputId($this->model, $this->attribute);
$field = $this->render('_field', ['fieldClass' => 'field-' . $inputId, 'inputId' => $inputId, 'inputName' => Html::getInputName($this->model, $this->attribute) . '[]', 'inputLabel' => $this->model->getAttributeLabel($this->attribute)]);
$options = Json::htmlEncode(['field' => $field, 'firstAddTogglerText' => 'добавить свою категорию', 'addTogglerText' => 'добавить ещё', 'values' => $this->model->{$this->attribute}]);
$this->view->registerJs('jQuery("#' . $this->id . '").kategoriiSlushatelejInputFields(' . $options . ');');
return Html::tag('div', $this->renderFirstToggler(), ['id' => $this->id, 'class' => 'kategorii-slushatelej-input-fields']);
}
示例4: registerClientScript
/**
* Registers the needed client script and options.
*/
public function registerClientScript()
{
$selector = $this->_selector;
$options = Json::htmlEncode($this->pluginOptions);
$clientScript = new JsExpression("\$('{$selector}').tokenfield({$options});");
$this->view->registerJs(Json::htmlEncode($clientScript), View::POS_LOAD);
}
示例5: init
public function init()
{
$id = $this->getId();
$options = Json::htmlEncode(ArrayHelper::merge($this->options, ['uploader' => ['backendUrl' => Url::to($this->url)], 'files' => $this->getFiles(), 'multiple' => $this->multiple]));
$this->getView()->registerJs("jQuery('#{$id}').fileInput({$options})");
echo Html::activeHiddenInput($this->model, $this->attribute, ['id' => $id]);
}
示例6: registerClientScript
private function registerClientScript()
{
$view = $this->getView();
TemaPickerAsset::register($view);
$options = Json::htmlEncode(['temaIndexUrl' => Url::to($this->temaIndexAction), 'temaFilterOptionsUrl' => Url::to($this->temaFilterOptionsAction), 'filterAttributes' => ['podrazdel', 'prepodavatel_fiz_lico', 'prepodavatel_strukturnoe_podrazdelenie', 'nedelya']]);
$view->registerJs('$("#' . $this->getId() . '").temaPicker(' . $options . ');');
}
示例7: testHtmlEncode
public function testHtmlEncode()
{
// HTML escaped chars
$data = '&<>"\'/';
$this->assertSame('"\\u0026\\u003C\\u003E\\u0022\\u0027\\/"', Json::htmlEncode($data));
// basic data encoding
$data = '1';
$this->assertSame('"1"', Json::htmlEncode($data));
// simple array encoding
$data = [1, 2];
$this->assertSame('[1,2]', Json::htmlEncode($data));
$data = ['a' => 1, 'b' => 2];
$this->assertSame('{"a":1,"b":2}', Json::htmlEncode($data));
// simple object encoding
$data = new \stdClass();
$data->a = 1;
$data->b = 2;
$this->assertSame('{"a":1,"b":2}', Json::htmlEncode($data));
// expression encoding
$expression = 'function () {}';
$data = new JsExpression($expression);
$this->assertSame($expression, Json::htmlEncode($data));
// complex data
$expression1 = 'function (a) {}';
$expression2 = 'function (b) {}';
$data = ['a' => [1, new JsExpression($expression1)], 'b' => new JsExpression($expression2)];
$this->assertSame("{\"a\":[1,{$expression1}],\"b\":{$expression2}}", Json::htmlEncode($data));
// https://github.com/yiisoft/yii2/issues/957
$data = (object) null;
$this->assertSame('{}', Json::htmlEncode($data));
// JsonSerializable
$data = new JsonModel();
$this->assertSame('{"json":"serializable"}', Json::htmlEncode($data));
}
示例8: run
public function run()
{
$id = $this->options['id'];
$options = Json::htmlEncode($this->getClientOptions());
$view = $this->getView();
EditorGridViewAsset::register($view);
$view->registerJs("jQuery('#{$id}').yiiGridView({$options});\$(document).off('change.yiiGridView keydown.yiiGridView');");
if ($this->showOnEmpty || $this->dataProvider->getCount() > 0) {
$content = preg_replace_callback("/{\\w+}/", function ($matches) {
$content = $this->renderSection($matches[0]);
return $content === false ? $matches[0] : $content;
}, $this->layout);
} else {
$content = $this->renderEmpty();
}
$options = $this->options;
$tag = ArrayHelper::remove($options, 'tag', 'div');
echo Html::tag($tag, $content, $options);
foreach ($this->columns as $column) {
if (isset($column->attribute) && $column->editable) {
$models = $this->dataProvider->getModels();
if (($model = reset($models)) instanceof Model) {
$name = Html::getInputName($model, $column->attribute);
} else {
$name = $column->attribute;
}
$attributeName = $column->attribute;
$view->registerJs("\$('.{$attributeName}').editable({\n placement:'right',\n ajaxOptions: {\n type: 'GET',\n dataType: 'json'\n },\n success: function(response, newValue) {\n if(response.status=='success')\n {\n return jQuery('#{$this->options['id']}').yiiGridView('applyFilter');\n }\n else\n {\n return response.msg;\n }\n },\n params: function(rawParams) {\n var params = {};\n params['{$name}']=rawParams.value;\n params['pk']=rawParams.pk;\n return params;\n }\n });");
}
}
}
示例9: registerClientOptions
/**
* Registers widget options
*/
private function registerClientOptions()
{
$id = $this->options['id'];
$options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
$js = "\$('#{$id}').slick({$options});";
$this->getView()->registerJs($js);
}
示例10: run
/**
* @inheritdoc
* @throw NotSupportedException
*/
public function run()
{
if ($this->hasModel()) {
if (!is_null($this->value)) {
if (!in_array($this->attribute, $this->model->attributes())) {
throw new NotSupportedException('Unable to set value of the property \'' . $this->attribute . '\'.');
}
$stash = $this->model->{$this->attribute};
$this->model->{$this->attribute} = $this->value;
}
$output = Html::activeListBox($this->model, $this->attribute, $this->items, $this->options);
if (isset($stash)) {
$this->model->{$this->attribute} = $stash;
}
} else {
$output = Html::listBox($this->name, $this->value, $this->items, $this->options);
}
$js = 'jQuery(\'#' . $this->options['id'] . '\').select2(' . Json::htmlEncode($this->clientOptions) . ');';
if (Yii::$app->getRequest()->getIsAjax()) {
$output .= Html::script($js);
} else {
$view = $this->getView();
Select2Asset::register($view);
Select2LanguageAsset::register($view);
$view->registerJs($js);
}
return $output;
}
示例11: registerClientScript
/**
* 注册FileAPI上传控制JS
*/
public function registerClientScript()
{
$options = Json::htmlEncode($this->getClientOptions());
$view = $this->getView();
FileApiAsset::register($view);
$view->registerJs("\$('#{$this->getId()}').fileapi({$options});");
}
示例12: registerPlugin
protected function registerPlugin()
{
$this->registerAssets();
$clientOptions = Json::htmlEncode($this->clientOptions);
$this->view->registerJs("jQuery('#{$this->options['id']}').clockpicker({$clientOptions});");
$this->registerClientEvents();
}
示例13: hashPluginOptions
/**
* Generates a hashed variable to store the plugin `clientOptions`. Helps in reusing the variable for similar
* options passed for other widgets on the same page. The following special data attribute will also be
* added to the input field to allow accessing the client options via javascript:
*
* @param View $view the view instance
*/
protected function hashPluginOptions($view)
{
$encOptions = empty($this->clientOptions) ? '{}' : Json::htmlEncode($this->clientOptions);
$this->_hashVar = self::PLUGIN_NAME . '_' . hash('crc32', $encOptions);
$this->options['data-plugin-' . self::PLUGIN_NAME] = $this->_hashVar;
$view->registerJs("var {$this->_hashVar} = {$encOptions};", View::POS_READY);
}
示例14: registerClientScript
private function registerClientScript()
{
$searchFormId = Json::htmlEncode("#{$this->getBulkFormId()}");
$view = $this->getView();
$view->registerJs(<<<JS
// Checkbox
var checkboxes = \$('table input[type="checkbox"]');
var bulkcontainer = \$('.box-bulk-actions fieldset');
checkboxes.on('ifChecked ifUnchecked', function(event) {
if (event.type == 'ifChecked' && \$('input.icheck').filter(':checked').length > 0) {
bulkcontainer.prop('disabled', false);
} else if (\$('input.icheck').filter(':checked').length == 0) {
bulkcontainer.prop('disabled', true);
}
});
// On/Off Actions TODO: reduce scope
\$(document).on('click', '.box-bulk-actions a', function (event) {
var link = \$(this);
var action = link.data('action');
var form = \$({$searchFormId});
if (action) {
form.attr({'action': action, method: 'POST'}).submit();
}
});
JS
, $view::POS_READY);
}
示例15: register
public function register()
{
$this->traitRegister();
if ($this->jsNotifier) {
Yii::$app->on(\yii\web\Application::EVENT_BEFORE_ACTION, function ($event) {
Yii::$app->view->on(\yii\web\View::EVENT_BEFORE_RENDER, function ($event) {
$host = $this->errbit['host'];
if (Url::isRelative($host)) {
$host = '//' . $host;
}
$event->sender->registerJsFile(rtrim($host, '/') . '/javascripts/notifier.js', ['position' => \yii\web\View::POS_HEAD]);
$js = 'Airbrake.setKey(' . Json::htmlEncode($this->errbit['api_key']) . ');';
$js .= 'Airbrake.setHost(' . Json::htmlEncode($this->errbit['host']) . ');';
if (isset($this->errbit['environment_name'])) {
$js .= 'Airbrake.setEnvironment(' . Json::htmlEncode($this->errbit['environment_name']) . ');';
}
if (is_array($this->jsOptions)) {
foreach ($this->jsOptions as $key => $value) {
$js .= 'Airbrake.set' . ucfirst($key) . '(' . Json::htmlEncode($value) . ');';
}
}
$controller = Yii::$app->controller;
if ($controller !== null && $controller instanceof UserInfoInterface) {
$user = $controller->getErrbitUserInfo();
if (is_array($user)) {
$js .= 'Airbrake.setCurrentUser(' . Json::htmlEncode($user) . ');';
}
}
$event->sender->registerJs($js, \yii\web\View::POS_HEAD);
});
});
}
}