php yii-helpers-Html类(方法)实例源码

下面列出了php yii-helpers-Html 类(方法)源码代码实例,从而了解它的用法。

作者:dosh9    项目:sho   
/**
  * Lists all StaticPageTable models.
  * @return mixed
  */
 public function actionIndex()
 {
     if (!Yii::$app->user->can('static-page-table/index')) {
         Yii::$app->session->setFlash('error', 'Нет доступа!');
         return $this->redirect('/');
     }
     if (isset($_POST['sort_list_2'])) {
         $mas = explode(',', $_POST['sort_list_2']);
         for ($i = 0; $i <= sizeof($mas) - 1; $i++) {
             $model = $this->findModel($mas[$i]);
             $model->position = $i;
             $model->save();
         }
     }
     $staticPagesTrue = StaticPageTable::find()->where(['status' => 1])->orderBy(['position' => SORT_ASC])->all();
     $staticPagesFalse = StaticPageTable::find()->where(['status' => 0])->orderBy(['position' => SORT_ASC])->all();
     $list = [];
     $value = "";
     foreach ($staticPagesTrue as $statispage) {
         $list[$statispage->id] = ['content' => Html::a(FA::icon($statispage->icon) . " " . $statispage->name, ['view', 'url' => $statispage->url])];
         $value .= $statispage->id . ",";
     }
     foreach ($staticPagesFalse as $statispage) {
         $list[$statispage->id] = ['content' => Html::a(FA::icon($statispage->icon) . " " . $statispage->name, ['view', 'url' => $statispage->url]), 'disabled' => true];
         $value .= $statispage->id . ",";
     }
     $value = substr($value, 0, -1);
     return $this->render('index', ['list' => $list, 'value' => $value]);
 }

作者:kennyg    项目:yii-mywe   
/**
  * Lists all Articlecomment models.
  * @return mixed
  */
 public function actionIndex()
 {
     $list = '';
     $post = Yii::$app->request->post();
     if ($post['id']) {
         $mod = new Query();
         $comment = $mod->select(['a.id', 'a.parentId', 'a.articleId', 'a.content', 'a.createTime', 'b.username'])->from('articlecomment as a')->leftJoin('user as b', 'a.userId = b.id')->where(['commentId' => $post['id']])->orderBy(['createTime' => 'DESC', 'id' => 'DESC'])->createCommand()->queryAll();
         if ($comment) {
             foreach ($comment as $v) {
                 $content = '回复@' . Articlecomment::getCommentByParId($v['parentId']) . ':' . $v['content'];
                 $ahtml = html::a(html::tag("i", "", ["class" => "fa fa-thumbs-o-up"]) . html::tag("span", "回复"), ["/main/viewart", "id" => $v["articleId"], "parId" => $v['id']]);
                 $list .= '<div class="infos small-comment' . $post['id'] . '" style="border:1px solid;">
                         	<div class="media-body markdown-reply content-body">
                         		<p>' . $content . '</p>
                         		<span class="opts pull-right">
                         			<a class="author" >' . $v["username"] . '</a>
                         			•
                         			<addr title="' . $v["createTime"] . '">' . Html::tag("span", Yii::$app->formatter->asRelativeTime($v["createTime"])) . '</addr>
                         			' . $ahtml . '
                                 </span>
                         	</div>
                         </div>';
             }
         }
     }
     $result = array('success' => true, 'message' => $list);
     echo json_encode($result);
     die;
     return $this->renderAjax('index', ['success' => true, 'message' => '']);
 }

作者:thrie    项目:yii2-statrepor   
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;
 }

作者:Polymedi    项目:BI-Platform-v   
public function run()
 {
     SelectAsset::register($this->view);
     FilterAsset::register($this->view);
     $values = [];
     foreach ($this->data as $value) {
         $value = strval($value);
         $values[$value] = $value;
     }
     if (!$this->default) {
         $this->default = $this->multiple ? array_keys($values) : key($values);
     }
     $selected = $this->selected($this->default);
     // Setup options
     $options = ['id' => $this->name, 'name' => $this->name . '[]', 'style' => 'width: 300px;', 'class' => 'selectpicker'];
     $extra = ['title' => 'Not selected'];
     if ($this->multiple) {
         $extra['multiple'] = 'multiple';
     }
     if ($this->placeholder) {
         $extra['title'] = strval($this->placeholder);
     }
     $options = array_merge($options, $extra);
     if (!$this->method) {
         $this->method = 'get';
     }
     // Render
     echo Html::beginForm(Url::canonical(), $this->method, ['data-pjax' => '1', 'id' => $this->name]);
     echo Html::beginTag('select', $options, ['data-pjax' => '1']);
     echo Html::renderSelectOptions($selected, $values);
     echo Html::endTag("select");
     echo Html::endForm();
     parent::run();
 }

作者:hiqde    项目:hipanel-module-dn   
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]);
         }]);
     }]]];
 }

作者:zydecod    项目:yii2-uiki   
/**
  * Initializes the widget options.
  * This method sets the default values for various options.
  */
 protected function initOptions()
 {
     if ($this->showButton) {
         Html::addCssClass($this->options, 'uk-button');
     }
     $this->options = array_merge(['data-uk-smooth-scroll' => ''], $this->options);
 }

作者:anl    项目:yii2-rba   
/**
  * @return string $template
  * @return mixed
  */
 public function actions($template = '{update} {delete}')
 {
     $this->columns = array_merge($this->columns, [['class' => ActionColumn::className(), 'controller' => SELF::CONTROLLER, 'template' => $template, 'buttons' => ['update' => function ($url, $model, $key) {
         return Html::a('<i class="fa fa-pencil"></i>', false, ['value' => Url::to([SELF::CONTROLLER . '/update', 'id' => $model->id]), 'title' => 'Update', 'class' => 'showModalButton']);
     }], 'contentOptions' => ['class' => 'text-right']]]);
     return $this;
 }

作者:luoch    项目:iisn   
/**
  * Renders the widget.
  */
 public function run()
 {
     echo Html::endTag('div');
     //closes the container, opened on init
     $this->infiniteScrollScript();
     $this->registerPlugin();
 }

作者:antiqwert    项目:yii2-gtreetable-fi   
public function run($id)
 {
     $model = $this->getNodeById($id);
     $model->scenario = 'move';
     $model->load(Yii::$app->request->post(), '');
     if (!$model->validate()) {
         throw new HttpException(500, current(current($model->getErrors())));
     }
     if (!$model->relatedNode instanceof $this->treeModelName) {
         throw new NotFoundHttpException(Yii::t('gtreetable', 'Position indicated by related ID is not exists!'));
     }
     try {
         if (is_callable($this->beforeAction)) {
             call_user_func_array($this->beforeAction, ['model' => $model]);
         }
         $action = $this->getMoveAction($model);
         if (!call_user_func(array($model, $action), $model->relatedNode)) {
             throw new Exception(Yii::t('gtreetable', 'Moving operation `{name}` failed!', ['{name}' => Html::encode((string) $model)]));
         }
         if (is_callable($this->afterAction)) {
             call_user_func_array($this->afterAction, ['model' => $model]);
         }
         echo Json::encode(['id' => $model->getPrimaryKey(), 'name' => $model->getName(), 'level' => $model->getLevel(), 'type' => $model->getType()]);
     } catch (\Exception $e) {
         throw new HttpException(500, $e->getMessage());
     }
 }

作者:fourteenmeiste    项目:yii2-semantic-u   
public function renderLabel()
 {
     if (!isset($this->labelOptions['for'])) {
         $this->labelOptions['for'] = $this->inputOptions['id'];
     }
     return $this->hasModel() ? Html::activeLabel($this->model, $this->attribute, $this->labelOptions) : Html::label($this->label, $this->labelOptions['for'], $this->labelOptions);
 }

作者:su-xiaoli    项目:yii2-mak   
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);
 }

作者:sintre    项目:yii2-basi   
public function sendMail()
 {
     /* @var $user User */
     $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]);
     if ($user) {
         if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
             $user->generatePasswordResetToken();
         }
         if ($user->save()) {
             $setting = Setting::find()->where(['id' => 1])->one();
             $username = $setting->sendgridUsername;
             $password = $setting->sendgridPassword;
             $mail_admin = $setting->emailAdmin;
             $sendgrid = new \SendGrid($username, $password, array("turn_off_ssl_verification" => true));
             $email = new \SendGrid\Email();
             $mail = $user->email;
             //echo $user->email;exit(0);
             $resetLink = \Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
             $body_message = 'Hello ' . Html::encode($user->username) . ', <br>
             Follow the link below to reset your password:  <br>
             ' . Html::a(Html::encode($resetLink), $resetLink);
             $email->addTo($user->email)->setFrom($mail_admin)->setSubject('Password reset for ' . \Yii::$app->name)->setHtml($body_message);
             $response = $sendgrid->send($email);
             //print_r($response); exit(0);
             return $response;
         }
     }
     return false;
 }

作者:madan    项目:yii2-clockpicke   
public function run()
 {
     if ($this->hasModel()) {
         return Html::activeTextInput($this->model, $this->attribute, $this->options);
     }
     return Html::textInput($this->name, $this->value, $this->options);
 }

作者:cj    项目:yii2-playgroun   
public function actionIndex()
 {
     $actions = [];
     $rc = new \ReflectionClass($this);
     $publicMethods = $rc->getMethods(\ReflectionMethod::IS_PUBLIC);
     $availableActions = [];
     foreach ($publicMethods as $publicMethod) {
         $methodName = $publicMethod->name;
         if ($methodName == 'actions') {
             continue;
         }
         if (StringHelper::startsWith($methodName, 'action')) {
             $availableActions[] = $methodName;
         }
     }
     if (count($this->actions()) > 0) {
         $availableActions = $availableActions + array_keys($this->actions());
     }
     $menus = [];
     foreach ($availableActions as $actionName) {
         $routeId = Inflector::camel2id(substr($actionName, strlen('action')));
         $menus[] = Html::a($actionName, [$routeId]);
     }
     echo implode('<br/>', $menus);
 }

作者:thedollarsig    项目:yii2-adminlte-them   
protected function renderItems($items)
 {
     $n = count($items);
     $lines = [];
     foreach ($items as $i => $item) {
         $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', []));
         $tag = ArrayHelper::remove($options, 'tag', 'li');
         $class = [];
         if ($item['active']) {
             $class[] = $this->activeCssClass;
         }
         if ($i === 0 && $this->firstItemCssClass !== null) {
             $class[] = $this->firstItemCssClass;
         }
         if ($i === $n - 1 && $this->lastItemCssClass !== null) {
             $class[] = $this->lastItemCssClass;
         }
         $menu = $this->renderItem($item);
         if (!empty($item['items'])) {
             $class[] = $this->treeClass;
             $menu .= strtr($this->submenuTemplate, ['{items}' => $this->renderItems($item['items'])]);
         }
         if (!empty($class)) {
             if (empty($options['class'])) {
                 $options['class'] = implode(' ', $class);
             } else {
                 $options['class'] .= ' ' . implode(' ', $class);
             }
         }
         $lines[] = Html::tag($tag, $menu, $options);
     }
     return implode("\n", $lines);
 }

作者:frostiks2    项目:rzwebsys   
/**
  * Возвращает массив скартой сайта
  * @return array
  * @throws InvalidConfigException
  */
 public function getElements()
 {
     $elements = [];
     foreach ($this->definition as $item) {
         if (empty($item["class"]) || empty($item["urlCreate"])) {
             throw new InvalidConfigException("Class or url create function missing");
         }
         $query = $item["class"]::find();
         $scopes = !empty($item["scopes"]) ? $item["scopes"] : [$this->defaultScope];
         $labelAttr = !empty($item["labelAttr"]) ? $item["labelAttr"] : $this->defaultLabelAttr;
         $this->applyScopes($query, $scopes);
         if ($query instanceof TActiveQuery) {
             $query->orderBy(["lft" => SORT_ASC]);
         } else {
             $query->orderBy(["id" => SORT_DESC]);
         }
         $iterator = $query->each();
         $arr = [];
         $arr['header'] = !empty($item["entityLabel"]) && is_callable($item["entityLabel"]) ? call_user_func($item["entityLabel"]) : $item["class"]::getEntityName();
         if (!empty($item["entityRoute"])) {
             $arr['entityUrl'] = Url::toRoute($item["entityRoute"]);
         }
         $arr['items'] = [];
         foreach ($iterator as $model) {
             if (empty($model->{$labelAttr}) or !empty($item["doAdd"]) and !call_user_func($item["doAdd"], $model)) {
                 continue;
             }
             $arr['items'][] = ["label" => $model->{$labelAttr}, "url" => Html::encode(call_user_func($item["urlCreate"], $model)), "date" => $model->updated_at];
         }
         $elements[] = $arr;
     }
     return $elements;
 }

作者:Razzwa    项目:dotplant   
public function init()
 {
     $url = is_array($this->route) ? Url::to($this->route) : Url::to([$this->route, 'term' => 'QUERY']);
     $this->dataset = [['remote' => ['url' => $url, 'wildcard' => 'QUERY'], 'templates' => ['empty' => Html::tag('span', Yii::t('app', 'Hit enter to search'), ['class' => 'empty-search']), 'suggestion' => new JsExpression("Handlebars.compile('{$this->template}')")]]];
     $this->pluginOptions = ['hint' => false];
     parent::init();
 }

作者:vsgut    项目:cr   
public function run()
 {
     if ($this->footerWrapper) {
         echo Html::beginTag('div', ['class' => 'form-group panel-footer']);
     }
     $submit_options = [];
     if ($this->form) {
         $submit_options['form'] = $this->form;
     }
     $extra = '';
     if ($this->extraBtns) {
         $extra = '&nbsp;' . implode(' ', (array) $this->extraBtns);
     }
     if (isset($this->model->isNewRecord) && $this->model->isNewRecord) {
         if ($this->saveLink) {
             $submit_options['class'] = 'btn btn-success';
             echo Html::submitButton(__('Create'), $submit_options);
         }
         echo $extra;
     } else {
         if ($this->saveLink) {
             $submit_options['class'] = 'btn btn-primary';
             echo Html::submitButton(__('Update'), $submit_options);
         }
         echo $extra;
         if ($this->removeLink) {
             echo ' ';
             echo Html::a(__('Delete'), ['delete', 'id' => $this->model->id], ['class' => 'btn btn-danger', 'data-confirm' => __('Are you sure you want to delete this item?'), 'data-method' => 'post']);
         }
     }
     if ($this->footerWrapper) {
         echo Html::endTag('div');
     }
 }

作者:gromve    项目:yii2-widget   
public function run()
 {
     echo Html::beginTag('img', $this->options);
     $this->options['src'] = ArrayHelper::remove($this->options, 'data-src');
     Html::removeCssClass($this->options, 'lazy');
     echo '<noscript>' . Html::beginTag('img', $this->options) . '</noscript>';
 }

作者:havenno    项目:sageone_tes   
public function actionIndex()
 {
     $model = new UploadForm();
     if (Yii::$app->request->isPost) {
         $model->file = UploadedFile::getInstance($model, 'file');
         $ext = $model->file->extension;
         $file_name = $model->file->baseName . '.' . $model->file->extension;
         if ($model->upload()) {
             if ($ext == 'csv') {
                 $erros = $this->ConverterCSV($file_name);
             }
             if ($ext == 'txt') {
                 $erros = $this->ConverterTXT($file_name);
             }
             if ($erros == NULL) {
                 $link = Html::a('Ver em produtos', ['/produto'], ['class' => 'btn btn-primary']);
                 \Yii::$app->getSession()->setFlash('success', 'Dados importados! ' . $link . '');
             } else {
                 if (is_array($erros)) {
                     $texto_erro = "";
                     foreach ($erros as $erro) {
                         $texto_erro .= $erro . '<br/>';
                     }
                     \Yii::$app->getSession()->setFlash('error', $texto_erro);
                 }
             }
         }
     }
     return $this->render('index', ['model' => $model]);
 }


问题


面经


文章

微信
公众号

扫码关注公众号