本文整理汇总了PHP中yii\helpers\Html::encode方法的典型用法代码示例。如果您正苦于以下问题:PHP Html::encode方法的具体用法?PHP Html::encode怎么用?PHP Html::encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Html
的用法示例。
在下文中一共展示了Html::encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toArray
public function toArray()
{
$response = [];
$response['status'] = $this->status;
$response['table'] = [];
$response['chart'] = [];
if ($response['status'] == static::STATUS_SUCCESS) {
if ($this->caption) {
$response['caption'] = $this->caption;
}
foreach ($this->data as $key => $row) {
$tableRow = [];
$chartRow = [];
foreach ($this->dataSeries as $s) {
if ($s->value !== null) {
$value = call_user_func($s->value, $row, $key);
} else {
$value = ArrayHelper::getValue($row, $s->name);
}
$value = $s->encode ? Html::encode($value) : $value;
$tableRow[] = $value;
if ($s->isInChart) {
$chartRow[] = $value;
}
}
$response['table'][] = $tableRow;
$response['chart'][] = $chartRow;
}
} else {
$response['message'] = $this->message;
}
return $response;
}
示例2: renderItems
/**
* Renders menu items.
* @param array $items the menu items to be rendered
* @return string the rendering result.
* @throws InvalidConfigException if the label option is not specified in one of the items.
*/
protected function renderItems($items)
{
$lines = [];
foreach ($items as $i => $item) {
if (isset($item['visible']) && !$item['visible']) {
unset($items[$i]);
continue;
}
if (is_string($item)) {
$lines[] = $item;
continue;
}
if (!isset($item['title'])) {
throw new InvalidConfigException("The 'title' option is required.");
}
$title = $this->encode ? Html::encode($item['title']) : $item['title'];
$titleOptions = ArrayHelper::getValue($item, 'titleOptions', []);
Html::addCssClass($titleOptions, 'list-group-item-heading');
$titleCode = Html::tag('h4', $title, $titleOptions);
$description = $this->encode ? Html::encode($item['description']) : $item['description'];
$descriptionOptions = ArrayHelper::getValue($item, 'descriptionOptions', []);
Html::addCssClass($descriptionOptions, 'list-group-item-text');
$descriptionCode = Html::tag('p', $description, $descriptionOptions);
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
Html::addCssClass($linkOptions, 'list-group-item');
Html::addCssStyle($linkOptions, 'word-wrap: break-word');
if (isset($item['active']) && $item['active']) {
Html::addCssClass($linkOptions, 'active');
}
$linkOptions['tabindex'] = '-1';
$lines[] = Html::a($titleCode . "\n" . $descriptionCode, ArrayHelper::getValue($item, 'url', '#'), $linkOptions);
}
return Html::tag('div', implode("\n", $lines), $this->options);
}
示例3: renderItems
/**
* Renders menu items.
* @param array $items the menu items to be rendered
* @return string the rendering result.
* @throws InvalidConfigException if the label option is not specified in one of the items.
*/
protected function renderItems($items)
{
$lines = [];
foreach ($items as $i => $item) {
if (isset($item['visible']) && !$item['visible']) {
unset($items[$i]);
continue;
}
if (is_string($item)) {
$lines[] = $item;
continue;
}
if (!isset($item['label'])) {
throw new InvalidConfigException("The 'label' option is required.");
}
$label = $this->encodeLabels ? Html::encode($item['label']) : $item['label'];
$options = ArrayHelper::getValue($item, 'options', []);
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
$linkOptions['tabindex'] = '-1';
$content = Html::a($label, ArrayHelper::getValue($item, 'url', '#'), $linkOptions);
if (isset($item['items'])) {
Html::addCssClass($options, 'has-dropdown');
$content .= FoundationNavDropDown::widget(['items' => $item['items']]);
}
$lines[] = Html::tag('li', $content, $options);
}
return Html::tag('ul', implode("\n", $lines), $this->options);
}
示例4: actionConfirm
public function actionConfirm()
{
$table = new Users();
if (Yii::$app->request->get()) {
//Obtenemos el valor de los parámetros get
$id = Html::encode($_GET["id"]);
$authKey = $_GET["authKey"];
if ((int) $id) {
//Realizamos la consulta para obtener el registro
$model = $table->find()->where("id=:id", [":id" => $id])->andWhere("authKey=:authKey", [":authKey" => $authKey]);
//Si el registro existe
if ($model->count() == 1) {
$activar = Users::findOne($id);
$activar->activate = 1;
if ($activar->update()) {
echo "Enhorabuena registro llevado a cabo correctamente, redireccionando ...";
echo "<meta http-equiv='refresh' content='8; " . Url::toRoute("site/login") . "'>";
} else {
echo "Ha ocurrido un error al realizar el registro, redireccionando ...";
echo "<meta http-equiv='refresh' content='8; " . Url::toRoute("site/login") . "'>";
}
} else {
//Si no existe redireccionamos a login
return $this->redirect(["site/login"]);
}
} else {
//Si id no es un número entero redireccionamos a login
return $this->redirect(["site/login"]);
}
}
}
示例5: roleName
/**
* @return mixed
*/
public function roleName()
{
$this->columns = array_merge($this->columns, [['attribute' => 'role_id', 'value' => function ($model, $key, $index, $column) {
return isset($model->role_id) ? Html::encode($model->role->name) : '';
}]]);
return $this;
}
示例6: renderItems
protected function renderItems($items, $options = [])
{
$lines = [];
foreach ($items as $i => $item) {
if (isset($item['visible']) && !$item['visible']) {
continue;
}
if (is_string($item)) {
$lines[] = $item;
continue;
}
if (!array_key_exists('label', $item)) {
throw new InvalidConfigException("The 'label' option is required.");
}
$encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
$label = $encodeLabel ? Html::encode($item['label']) : $item['label'];
$itemOptions = ArrayHelper::getValue($item, 'options', []);
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
$linkOptions['tabindex'] = '-1';
$url = array_key_exists('url', $item) ? $item['url'] : null;
if (empty($item['items'])) {
if ($url === null) {
$content = $label;
} else {
$content = Html::a($label, $url, $linkOptions);
}
} else {
$submenuOptions = $options;
unset($submenuOptions['id']);
$content = Html::a($label, $url === null ? '#' : $url, $linkOptions) . $this->renderItems($item['items'], $submenuOptions);
}
$lines[] = Html::tag('li', $content, $itemOptions);
}
return Html::tag('ul', implode("\n", $lines), $options);
}
示例7: role
/**
* @return mixed
*/
public function role()
{
$this->columns = array_merge($this->columns, [['header' => 'role', 'value' => function ($model, $key, $index, $column) {
return $model->getUserRole()->exists() ? Html::encode($model->userRole->role->name) : '';
}]]);
return $this;
}
示例8: saveTag
/**
* @param $tagArray
* @return array
*/
public function saveTag($tagArray)
{
$saveTags = [];
if (is_array($tagArray)) {
foreach ($tagArray as $tag) {
if ($tagObj = $this->find()->where('value=:value', [':value' => $tag])->one()) {
$saveTags[] = $tagObj->tag_id;
} else {
if (!$this->find()->where('tag_id=:tag_id', [':tag_id' => (int) $tag])->exists()) {
$this->value = \yii\helpers\Html::encode($tag);
if ($this->save()) {
$saveTags[] = $this->tag_id;
$this->setIsNewRecord(true);
unset($this->tag_id);
} else {
return ['error' => $this->errors['value'][0]];
}
} else {
$saveTags[] = $tag;
}
}
}
}
return $saveTags;
}
示例9: actionMonth
public function actionMonth($y = null, $m = null)
{
$m = Html::encode($m);
$y = Html::encode($y);
$model = yii::$app->orderModel;
return $this->render('month', ['m' => $m, 'y' => $y, 'month' => yii::t('order', "month_{$m}"), 'model' => $model]);
}
示例10: nameWithLink
/**
* @return mixed
*/
public function nameWithLink()
{
$this->columns = array_merge($this->columns, [['attribute' => 'name', 'value' => function ($model, $key, $index, $column) {
return Html::a(Html::encode($model->name), [SELF::CONTROLLER . '/view', 'id' => $model->id]);
}, 'format' => 'raw']]);
return $this;
}
示例11: getDescription
/**
* Описание
* @param $desc
* @return string
*/
public static function getDescription($desc)
{
if (empty($desc)) {
return 'Нет описания';
}
return Html::encode($desc);
}
示例12: actionSendMessage
/**
* Отправка сообщения
*/
public function actionSendMessage()
{
$message = Html::encode($_POST['message']);
$recipient = intval($_POST['recipient']);
$id = ChatMessage::createNew($message, $recipient)->id;
echo json_encode(['id' => $id]);
}
示例13: renderItem
/**
* @inheritdoc
*/
public function renderItem($item)
{
if (is_string($item)) {
return $item;
}
if (!isset($item['label'])) {
throw new InvalidConfigException("The 'label' option is required.");
}
$encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
$label = $encodeLabel ? Html::encode($item['label']) : $item['label'];
$options = ArrayHelper::getValue($item, 'options', []);
$items = ArrayHelper::getValue($item, 'items');
$url = ArrayHelper::getValue($item, 'url', '#');
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
if (isset($item['active'])) {
$active = ArrayHelper::remove($item, 'active', false);
} else {
$active = $this->isItemActive($item);
}
Html::addCssClass($linkOptions, 'filter-item');
if ($this->activateItems && $active) {
Html::addCssClass($linkOptions, 'selected');
}
return Html::tag('li', Html::a($label, $url, $linkOptions) . $items, $options);
}
示例14: echoEncodeString
public static function echoEncodeString($string, $default = '')
{
if ($string != '0') {
$string = $string ? $string : $default;
}
return Html::encode($string);
}
示例15: actionSearch
/**
* Provides a searchable user list of all workspace members in json.
*
*/
public function actionSearch()
{
Yii::$app->response->format = 'json';
$space = $this->getSpace();
if (!$space->isMember()) {
throw new HttpException(404, Yii::t('SpaceModule.controllers_SpaceController', 'This action is only available for workspace members!'));
}
$results = array();
$keyword = Yii::$app->request->get('keyword');
$query = User::find();
$query->leftJoin('space_membership', 'space_membership.user_id=user.id AND space_membership.space_id=:space_id AND space_membership.status=:member', ['space_id' => $space->id, 'member' => Membership::STATUS_MEMBER]);
$query->andWhere('space_membership.space_id IS NOT NULL');
$query->joinWith('profile');
$query->limit(10);
// Build Search Condition
$parts = explode(" ", $keyword);
$i = 0;
foreach ($parts as $part) {
$i++;
$query->andWhere("(user.email LIKE :match OR " . "user.username LIKE :match OR " . "profile.firstname LIKE :match OR " . "profile.lastname LIKE :match OR " . "profile.title LIKE :match)", ['match' => '%' . $part . '%']);
}
foreach ($query->all() as $user) {
$userInfo['guid'] = $user->guid;
$userInfo['displayName'] = \yii\helpers\Html::encode($user->displayName);
$userInfo['email'] = $user->email;
$userInfo['image'] = $user->getProfileImage()->getUrl();
$userInfo['link'] = $user->getUrl();
$results[] = $userInfo;
}
return $results;
}