本文整理汇总了PHP中yii\helpers\Html::script方法的典型用法代码示例。如果您正苦于以下问题:PHP Html::script方法的具体用法?PHP Html::script怎么用?PHP Html::script使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Html
的用法示例。
在下文中一共展示了Html::script方法的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: init
public function init()
{
$value = $this->model->{$this->attribute};
if (is_int($value) || is_float($value) || is_string($value) && strlen($value)) {
$this->inputOptions['value'] = Text::date($this->dateFormat . $this->separator . $this->timeFormat, $value);
$this->hiddenInputOptions['value'] = Text::date($this->altDateFormat . $this->altSeparator . $this->altTimeFormat, $value);
}
if (!$this->readOnly) {
$pluginOptions = array_merge(['numberOfMonths' => 3, 'showButtonPanel' => true, 'altFieldTimeOnly' => false], $this->pluginOptions, ['dateFormat' => Text::juiDateFormat($this->dateFormat), 'altFormat' => Text::juiDateFormat($this->altDateFormat), 'separator' => $this->separator, 'altSeparator' => $this->altSeparator, 'timeFormat' => Text::juiTimeFormat($this->timeFormat), 'altTimeFormat' => Text::juiTimeFormat($this->altTimeFormat)]);
$inputId = Html::getInputId($this->model, $this->attribute);
$pluginOptions['altField'] = '#' . $inputId . '-alt';
$js = 'jQuery(\'#' . $inputId . '\').datetimepicker(' . Json::encode($pluginOptions) . ');';
$this->inputOptions['name'] = false;
$this->hiddenInputOptions['id'] = $inputId . '-alt';
$this->template .= "\n{hiddenInput}";
$this->parts['{hiddenInput}'] = Html::activeHiddenInput($this->model, $this->attribute, $this->hiddenInputOptions);
if (Yii::$app->getRequest()->getIsAjax()) {
$this->template .= "\n{script}";
$this->parts['{script}'] = Html::script($js);
} else {
$view = $this->form->getView();
TimePickerAsset::register($view);
$view->registerJs($js);
}
}
parent::init();
}
示例3: 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;
}
示例4: run
public function run()
{
$chatModel = new \nitm\widgets\models\Replies(['constrain' => ['type' => 'chat']]);
$notificationModel = new \nitm\widgets\models\Notification(['constrain' => ['user_id' => \Yii::$app->user->getId()], 'queryOptions' => ['read' => 0]]);
$uniqid = uniqid();
$chatWidget = Nav::widget(['encodeLabels' => false, 'options' => ['id' => 'communication-center-messages-wrapper' . $uniqid, 'class' => 'nav navbar-right navbar-nav'], 'items' => [['label' => Icon::show('comment') . Html::tag('span', $chatModel->hasNew(), ['class' => 'badge']), 'options' => ['class' => !$chatModel->hasNew() ? 'text-disabled' : 'text-success'], 'linkOptions' => ['id' => 'communication-center-messages-button' . $uniqid, 'title' => 'Click here again to refresh the info', 'role' => 'dynamicValue', 'data-run-once' => 1, 'data-animation-target' => '#chat' . $uniqid, 'data-animation-start-only' => 1, 'data-type' => 'html', 'data-id' => '#chat' . $uniqid, 'data-url' => \Yii::$app->urlManager->createUrl(['/reply/index/chat/0', '__format' => 'html', \nitm\widgets\models\Replies::FORM_PARAM => true])], 'items' => [['label' => Html::tag('div', Html::tag('h2', 'Loading Messages...', ['class' => 'text-center']) . Html::script('$("#communication-center-messages-button' . $uniqid . '").one("mouseover", function (event) {
$(this).trigger("click");
})', ['type' => 'text/javascript']), ['role' => 'chatParent', 'id' => 'chat' . $uniqid, 'class' => '']), 'options' => $this->contentOptions]]]]]);
$alertWidget = Nav::widget(['encodeLabels' => false, 'options' => ['id' => 'communication-center-notifications-wrapper' . $uniqid, 'class' => 'nav navbar-right navbar-nav'], 'items' => [['label' => Icon::show('bell') . Html::tag('span', $notificationModel->count(), ['class' => 'badge']), 'options' => ['class' => !$notificationModel->count() ? 'bg-disabled' : 'bg-success'], 'linkOptions' => ['id' => 'communication-center-notifications-button' . $uniqid, 'title' => 'Click here again to refresh the info', 'role' => 'dynamicValue', 'data-run-once' => 1, 'data-animation-target' => '#communication-center-notifications' . $uniqid, 'data-animation-start-only' => 1, 'data-type' => 'html', 'data-id' => '#communication-center-notifications' . $uniqid, 'data-url' => \Yii::$app->urlManager->createUrl(['/alerts/notifications', '__format' => 'html'])], 'items' => [['label' => Html::tag('div', Html::tag('h2', 'Loading Alerts...', ['class' => 'text-center']) . Html::script('$("#communication-center-notifications-button' . $uniqid . '").one("mouseover", function (event) {
$(this).trigger("click");
})', ['type' => 'text/javascript']), ['id' => 'communication-center-notifications' . $uniqid, 'class' => '']), 'options' => $this->contentOptions]]]]]);
$widget = $alertWidget . $chatWidget;
//$js = "\$nitm.onModuleLoad('communication-center', function (module) {
// module.initChatTabs('#".$this->options['id']."');
//});";
$js = "";
if ($this->chatUpdateOptions['enabled']) {
$js .= "\$nitm.onModuleLoad('polling', function (module) {\r\n\t\t\t\tmodule.initPolling('chat', {\r\n\t\t\t\t\tenabled: true,\r\n\t\t\t\t\turl: '" . $this->chatUpdateOptions['url'] . "', \r\n\t\t\t\t\tinterval: " . $this->chatUpdateOptions['interval'] . ",\r\n\t\t\t\t\tcontainer: '#nitm-communication-center-widget" . $uniqid . "'\r\n\t\t\t\t}, {object: \$nitm.module('replies'), method: 'chatStatus'});\r\n\t\t\t});";
}
if ($this->notificationUpdateOptions['enabled']) {
$js .= "\r\n\t\t\t\$nitm.onModuleLoad('polling', function (module) {\r\n\t\t\t\tmodule.initPolling('notifications', {\r\n\t\t\t\t\tenabled: true,\r\n\t\t\t\t\tinterval: " . $this->notificationUpdateOptions['interval'] . ",\r\n\t\t\t\t\turl: '" . $this->notificationUpdateOptions['url'] . "',\r\n\t\t\t\t\tcontainer: '#nitm-communication-center-widget" . $uniqid . "'\r\n\t\t\t\t}, {object: \$nitm.module('notifications'), method: 'notificationStatus'});\r\n\t\t\t});";
}
if ($js) {
$js = Html::script($js, ['type' => 'text/javascript']);
}
return $widget . $js;
}
示例5: 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;
}
示例6: actionUpload
/**
* загружает картинки в CKEDITOR
*/
public function actionUpload()
{
$this->actionUpload_clearTempFolder();
$fileInfo = pathinfo($_FILES['upload']['name']);
$path = UploadFolderDispatcher::createFolder(HtmlContent::$uploadFolder);
$path->add(time() . '_' . Security::generateRandomString(10) . '.' . $fileInfo['extension']);
if ($_FILES['upload'] == 'none' or empty($_FILES['upload']['name'])) {
$message = 'No file uploaded';
} else {
if ($_FILES['upload']['size'] == 0) {
$message = 'The file is of zero length';
} else {
if ($_FILES['upload']['type'] != 'image/jpeg' and $_FILES['upload']['type'] != 'image/png') {
$message = 'The image must be in either JPG or PNG format. Please upload a JPG or PNG instead';
} else {
if (!is_uploaded_file($_FILES['upload']['tmp_name'])) {
$message = "You may be attempting to hack our server. We're on to you; expect a knock on the door sometime soon";
} else {
$message = '';
$move = @move_uploaded_file($_FILES['upload']['tmp_name'], $path->getPathFull());
if (!$move) {
$message = 'Error moving uploaded file. Check the script is granted Read/Write/Modify permissions';
}
}
}
}
}
$funcNum = (int) $_GET['CKEditorFuncNum'];
return Html::script("window.parent.CKEDITOR.tools.callFunction({$funcNum}, '{$path->getPath()}', '{$message}');");
}
示例7: actionIndex
public function actionIndex()
{
$auth = \Yii::$app->authManager;
$nameItem = \Yii::$app->request->post()['name'];
$auth->removeRecursive($nameItem);
Yii::$app->session->setFlash('info', $_POST['type'] == 1 ? 'Роль успешно удалена.' : 'Разрешение успешно удалено.');
echo Html::script("\$('#rbacTree').jstree('refresh', true, true);");
return $this->renderAjax('@app/views/layouts/flash.php');
}
示例8: run
public function run()
{
$inputId = $this->options['id'];
$altInputId = $inputId . '-alt';
$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;
}
$altOptions = ['id' => $altInputId, 'name' => $altInputId];
if (!is_null($value) && $value !== '') {
$formatter = Yii::$app->getFormatter();
try {
$this->options['value'] = $formatter->asDate($value, $this->dateFormat) . self::SEPARATOR . $formatter->asTime($value, $this->timeFormat);
$altOptions['value'] = $formatter->asDate($value, $this->altDateFormat) . self::SEPARATOR . $formatter->asTime($value, $this->altTimeFormat);
} catch (InvalidParamException $e) {
// ignore exception and keep original value if it is not a valid date
}
}
if ($hasModel) {
$output = Html::activeTextInput($this->model, $this->attribute, $this->options) . (!$this->disableAlt ? Html::activeHiddenInput($this->model, $this->attribute, $altOptions) : null);
} else {
$output = Html::textInput($this->name, $this->value, $this->options) . (!$this->disableAlt ? Html::hiddenInput($this->name, $this->value, $altOptions) : null);
}
$this->clientOptions = array_merge(['numberOfMonths' => $this->numberOfMonths, 'showButtonPanel' => $this->showButtonPanel], $this->clientOptions, ['dateFormat' => FormatConverter::convertDatePhpOrIcuToJui($this->dateFormat), 'separator' => self::SEPARATOR, 'timeFormat' => FormatConverter::convertTimePhpOrIcuToJui($this->timeFormat), 'altFormat' => FormatConverter::convertDatePhpOrIcuToJui($this->altDateFormat), 'altSeparator' => self::SEPARATOR, 'altTimeFormat' => FormatConverter::convertTimePhpOrIcuToJui($this->altTimeFormat), 'altField' => '#' . $altInputId, 'altFieldTimeOnly' => false]);
if (!$this->ignoreReadonly && array_key_exists('readonly', $this->options) && $this->options['readonly']) {
$this->clientOptions['beforeShow'] = new JsExpression('function (input, inst) { return false; }');
}
if ($this->disableAlt) {
foreach ($this->clientOptions as $keyCO => $valueCO) {
if (strrpos($keyCO, 'alt') !== false) {
unset($this->clientOptions[$keyCO]);
}
}
}
$js = 'jQuery(\'#' . $inputId . '\').datetimepicker(' . Json::htmlEncode($this->clientOptions) . ');';
if (Yii::$app->getRequest()->getIsAjax()) {
$output .= Html::script($js);
} else {
$view = $this->getView();
JuiDatetimePickerAsset::register($view);
JuiDatetimePickerLanguageAsset::register($view);
$view->registerJs($js);
}
return $output;
}
示例9: run
public function run()
{
$title = Html::tag('h2', $this->header);
switch ($this->asForm) {
case true:
$metadata = $this->getAsForm();
break;
default:
$metadata = $this->getAsGrid();
break;
}
$script = Html::script(new \yii\web\JsExpression('$nitm.onModuleLoad("entity:metadata", function (module) {
module.initDefaults("#' . $this->options['id'] . '");
});'));
return $title . $metadata . $script;
}
示例10: init
public function init()
{
parent::init();
Cloud::getInst();
if (empty($this->name)) {
throw new InvalidConfigException('The "name" property must be set.');
}
$this->options['id'] = ArrayHelper::remove($this->options, 'id', $this->getId());
echo Html::script($this->getTemplate(), ['type' => 'text/template', 'id' => 'qq-template-gallery-' . $this->getId()]);
echo Html::tag('div', null, $this->options);
if ($this->filesPath && $this->filesUrlPath) {
$this->registerScript(true);
echo $this->showSavedFiles();
} else {
$this->registerScript();
}
}
示例11: run
/**
* @inheritdoc
*/
public function run()
{
if ($this->hasModel()) {
$output = Html::activeTextarea($this->model, $this->attribute, $this->options);
} else {
$output = Html::textarea($this->name, $this->value, $this->options);
}
$js = 'jQuery(\'#' . $this->options['id'] . '\').tinymce(' . Json::htmlEncode($this->clientOptions) . ');';
if (Yii::$app->getRequest()->getIsAjax()) {
$output .= Html::script($js);
} else {
$view = $this->getView();
TinymceAsset::register($view);
TinymceLanguageAsset::register($view);
$view->registerJs($js);
}
return $output;
}
示例12: init
public function init()
{
if ($this->readOnly) {
$pluginOptions = array_merge($this->pluginOptions, ['readonly' => true, 'menubar' => false, 'toolbar' => false, 'statusbar' => false]);
} else {
$pluginOptions = $this->pluginOptions;
}
$inputId = Html::getInputId($this->model, $this->attribute);
$pluginOptions['selector'] = '#' . $inputId;
$js = 'jQuery(\'#' . $inputId . '\').tinymce(' . Json::encode($pluginOptions) . ');';
if (Yii::$app->getRequest()->getIsAjax()) {
$this->template .= "\n{script}";
$this->parts['{script}'] = Html::script($js);
} else {
$view = $this->form->getView();
TinymceAsset::register($view);
$view->registerJs($js);
}
parent::init();
}
示例13: getNavigation
protected function getNavigation()
{
$new = $this->model->hasNew();
switch ($new >= 1) {
case true:
$newMessage = $new . " new messages";
$newClass = "bg-success";
break;
default:
$newMessage = 'No new messages';
$newClass = "bg-transparent";
break;
}
$uniqid = uniqid();
$ret_val = Tabs::widget(['options' => ['id' => 'nitm-chat-widget' . $uniqid], 'encodeLabels' => false, 'items' => [['label' => 'Messages ' . Html::tag('span', $this->model->hasNew(), ['class' => 'badge']), 'active' => false, 'content' => Html::tag('div', '', ['id' => 'chat-widget-container' . $uniqid, 'role' => 'chatParent', 'id' => 'chat' . $uniqid, 'class' => 'chat col-md-4 col-lg-4', 'style' => 'z-index: 10000; position: fixed;top: 6px; right: 6px;bottom: 40px;overflow: hidden;padding: 0px;box-shadow: 2px 2px 15px #000; background-color: rgba(153,153,153,0.9);']), 'options' => ['id' => 'chat-widget-messages' . $uniqid], 'headerOptions' => ['id' => 'chat-widget-messages-tab' . $uniqid], 'linkOptions' => ['role' => 'visibility', 'data-type' => 'html', 'data-on' => '#chat-widget-messages' . $uniqid . ':hidden', 'data-id' => '#chat' . $uniqid, 'data-url' => \Yii::$app->urlManager->createUrl(['/reply/index/chat/0', '__format' => 'html', \nitm\widgets\models\Replies::FORM_PARAM => true]), 'id' => 'chat-widget-messages-link' . $uniqid]], ['label' => '', 'content' => '', 'active' => true, 'headerOptions' => ['class' => 'hidden']]]]);
if (isset($this->updateOptions['enable']) && $this->updateOptions['enable']) {
$ret_val .= Html::script("\$nitm.module('replies').initChatActivity(\"[role='chatParent']\", '" . $this->updateOptions['url'] . "', " . $this->updateOptions['interval'] . ")");
}
return $ret_val;
}
示例14: run
public function run()
{
$vote = '';
switch (\Yii::$app->user->identity->isAdmin()) {
case true:
break;
}
switch (VoteModel::$individualCounts) {
case true:
$positive = Html::tag('div', Html::tag('strong', $this->model->rating()['positive'], ['id' => 'vote-value-positive' . $this->parentId]) . (VoteModel::$usePercentages ? '%' : ""), ['class' => 'text-success col-md-6 col-lg-6']);
$negative = Html::tag('div', Html::tag('strong', $this->model->rating()['negative'], ['id' => 'vote-value-negative' . $this->parentId]) . (VoteModel::$usePercentages ? '%' : ""), ['class' => 'text-danger col-md-6 col-lg-6']);
break;
default:
$negative = '';
$positive = Html::tag('strong', $this->model->rating()['positive'], ['id' => 'vote-value-positive' . $this->parentId]) . (VoteModel::$usePercentages ? "%" : '');
break;
}
$vote .= Html::tag('div', $positive . $negative, ['class' => 'center-block text-center']);
$vote .= $this->getActions();
$this->widgetOptions['id'] .= $this->parentId . $this->uniqid;
return Html::tag('div', $vote, $this->widgetOptions) . Html::script(new \yii\web\JsExpression("\$nitm.onModuleLoad('vote', function () {\$nitm.module('vote').init('" . $this->widgetOptions['id'] . "');});"));
}
示例15: actionIndex
public function actionIndex()
{
$auth = \Yii::$app->authManager;
$model = new rbacForm();
if (Yii::$app->request->isPjax && $model->load(Yii::$app->request->post()) && $model->validate()) {
$parent = $auth->getRole($model->parent);
$session = Yii::$app->session;
if ($model->type == 1) {
$role = $auth->createRole($model->name);
$role->description = $model->description;
$auth->add($role);
if ($model->parent) {
$auth->addChild($parent, $role);
}
$session->setFlash('success', 'Роль успешно создана.');
} else {
$permission = $auth->createPermission($model->name);
$permission->description = $model->description;
$auth->add($permission);
if ($model->parent) {
$auth->addChild($parent, $permission);
}
$session->setFlash('alerts', 'Разрешение успешно создано.');
}
echo $this->renderAjax('@app/views/layouts/response.php');
$model = new rbacForm();
$auth = \Yii::$app->authManager;
echo Html::script("if(\$('#rbacTree').length) { \$('#rbacTree').jstree('refresh', true, true);};");
return $this->render('index', ['model' => $model, 'auth' => $auth]);
}
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
return $this->render('index', ['model' => $model, 'auth' => $auth]);
}