本文整理汇总了PHP中yii\web\View类的典型用法代码示例。如果您正苦于以下问题:PHP View类的具体用法?PHP View怎么用?PHP View使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了View类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bizConfig
/**
*
* @param View $view
* @param array $data
*/
public static function bizConfig($view, $config = [], $position = View::POS_BEGIN)
{
$default = ['delay' => 1000, 'limit' => 20, 'checkStock' => false, 'debug' => YII_ENV == 'dev', 'pullUrl' => \yii\helpers\Url::to(['/master/sources/pull'])];
$js = "\n var biz = biz || {};" . "\n biz.config = " . Json::encode(ArrayHelper::merge($default, $config)) . ";\n";
$view->registerJs($js, $position);
BizAsset::register($view);
}
示例2: addAsset
/**
* Adds an asset to the view
*
* @param View $view The View object
* @param string $file The asset file name
* @param string $type The asset file type (css or js)
* @param string $class The class name of the AssetBundle
*
* @return void
*/
protected function addAsset($view, $file, $type, $class)
{
if ($type == 'css' || $type == 'js') {
$asset = $view->getAssetManager();
$bundle = $asset->bundles[$class];
if ($type == 'css') {
$bundle->css[] = $file;
} else {
$bundle->js[] = $file;
}
$asset->bundles[$class] = $bundle;
$view->setAssetManager($asset);
}
}
示例3: registerLanguage
/**
* @param string $language
* @param View $view
*/
public function registerLanguage($language, $view)
{
if (file_exists($this->sourcePath . "/locale/{$language}.js")) {
$this->js = array_merge($this->js, ['min/locales.min.js']);
$view->registerJsFile($this->baseUrl . "/locale/{$language}.js");
$js = <<<JS
moment.locale('{$language}');
JS;
$view->registerJs($js, View::POS_READY, 'moment-locale-' . $language);
}
}
示例4: registerAssetFiles
/**
* Registers the CSS and JS files with the given view.
* @param \yii\web\View $view the view that the asset files are to be registered with.
*/
public function registerAssetFiles($view)
{
$manager = $view->getAssetManager();
foreach ($this->css as $css) {
$view->registerCssFile($manager->getAssetUrl($this, $css), $this->cssOptions);
}
$view->registerJsFile($this->basketJs);
$jsFiles = [];
foreach ($this->js as $js) {
$jsFiles[] = Json::encode(['url' => $manager->getAssetUrl($this, $js)]);
}
$view->registerJs(sprintf('basket.require(%s);', implode(",\r\n", $jsFiles)), View::POS_END);
}
示例5: applyTo
/**
* @param View $view
*/
public function applyTo(View $view)
{
$attributes = $this->getAttributes(null, ['id', 'meta_id']);
foreach ($attributes as $name => $value) {
$view->registerMetaTag(['property' => 'twitter:' . $name, 'content' => $value]);
}
}
示例6: registerAssetFiles
/**
* Registers the CSS and JS files with the given view.
* @param \yii\web\View $view the view that the asset files are to be registered with.
*/
public function registerAssetFiles($view)
{
if ($this->configuration !== null) {
$view->registerJs('NProgress.configure(' . Json::encode($this->configuration) . ');');
}
$view->registerJs(<<<JS
jQuery(document).on('pjax:start', function() { NProgress.start(); });
jQuery(document).on('pjax:end', function() { NProgress.done(); });
JS
);
$view->registerJs(<<<JS
var exceptUrls = [
];
jQuery(document).on('ajaxSend', function(e, xhr, options) {
if( \$.inArray( options.url, exceptUrls ) == -1)
NProgress.start();
});
jQuery(document).on('ajaxComplete', function(e, xhr, options) {
if( \$.inArray( options.url, exceptUrls ) == -1 )
NProgress.done();
});
JS
);
parent::registerAssetFiles($view);
}
示例7: registerGlobalMetaTags
/**
* Register global meta tags like verifications and so on
*
* @param View $view
*/
protected static function registerGlobalMetaTags($view)
{
$globalMetaTags = Yii::$app->cache->get('__globalMetaTags');
if ($globalMetaTags === false) {
$globalMetaTags = GlobalMetaTag::find()->andWhere(['active' => 1])->asArray()->all();
Yii::$app->cache->set('__globalMetaTags', $globalMetaTags, 3600 * 24);
}
foreach ($globalMetaTags as $globalTag) {
$view->registerMetaTag(['name' => $globalTag['name'], 'content' => $globalTag['content']], $globalTag['name']);
}
}
示例8: initPlugin
/**
* Initializes plugin
* @param View $view
* @return $this
*/
public function initPlugin(View $view, $options = [])
{
$options = array_merge(['message' => Yii::t('mgcode/sessionWarning', 'Your session is going to expire at {time}.')], $options);
$json = Json::encode($options);
$view->registerJs("\$('#session-warning-modal').sessionWarning({$json});");
return $this;
}
示例9: sendMessage
public function sendMessage($to, $file, $params = [])
{
$view = new View();
$message = ['from' => $this->from, 'to' => $to, 'to' => '+8618670366212', 'text' => $view->render($file, $params)];
return;
//@todo remove
$this->getTransport()->send($message);
}
示例10: registerScripts
/**
* Register scripts
* @param View $view
*/
protected function registerScripts(\yii\web\View $view)
{
if ($this->clientOptions !== false) {
$options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions);
$js = "jQuery('#{$this->id}').fancybox({$options});";
$view->registerJs($js, View::POS_READY);
}
}
示例11: renderRazdelyTipa
/**
* @param View $view
* @param KursExtended $kursRecord
* @param mixed $tip
* @return string
*/
function renderRazdelyTipa($view, $kursRecord, $tip)
{
$ret = '';
$query = $kursRecord->getRazdelyKursaRel()->orderBy('nomer')->where(['tip' => TipRazdelaKursa::asSql($tip)]);
foreach ($query->all() as $razdelRecord) {
$ret .= $view->render('_razdel-kursa', compact('razdelRecord'));
}
return $ret;
}
示例12: registerSelect
/**
* Registers JS code to help initialize Select2 widgets
* with access to netis\crud\crud\ActiveController API.
* @param \yii\web\View $view
*/
public static function registerSelect($view)
{
$script = <<<JavaScript
(function (s2helper, \$, undefined) {
"use strict";
s2helper.formatResult = function (result, container, query, escapeMarkup, depth) {
if (typeof depth == 'undefined') {
depth = 0;
}
var markup = [];
window.Select2.util.markMatch(result._label, query.term, markup, escapeMarkup);
return markup.join("");
};
s2helper.formatSelection = function (item) {
return item._label;
};
// generates query params
s2helper.data = function (term, page) {
return { search: term, page: page };
};
// builds query results from ajax response
s2helper.results = function (data, page) {
return { results: data.items, more: page < data._meta.pageCount };
};
s2helper.getParams = function (element) {
var primaryKey = element.data('relation-pk');
if (typeof primaryKey === 'undefined' || primaryKey === null) {
primaryKey = 'id';
}
var params = {search: {}};
params.search[primaryKey] = element.val();
return params;
};
s2helper.initSingle = function (element, callback) {
\$.getJSON(element.data('select2').opts.ajax.url, s2helper.getParams(element), function (data) {
if (typeof data.items[0] != 'undefined') {
callback(data.items[0]);
}
});
};
s2helper.initMulti = function (element, callback) {
\$.getJSON(element.data('select2').opts.ajax.url, s2helper.getParams(element), function (data) {callback(data.items);});
};
}( window.s2helper = window.s2helper || {}, jQuery ));
JavaScript;
$view->registerJs($script, \yii\web\View::POS_END, 'netis.s2helper');
\maddoger\widgets\Select2BootstrapAsset::register($view);
}
示例13: registerPluginEvents
/**
* Registers plugin events
*
* @param View $view The View object
*/
protected function registerPluginEvents($view)
{
if (!empty($this->pluginEvents)) {
$id = 'jQuery("#' . $this->options['id'] . '")';
$js = [];
foreach ($this->pluginEvents as $event => $handler) {
$function = new JsExpression($handler);
$js[] = "{$id}.on('{$event}', {$function});";
}
$js = implode("\n", $js);
$view->registerJs($js);
}
}
示例14: registerLocaleInternal
/**
* @param \yii\web\View $view
* @throws \yii\base\InvalidConfigException If file with the locale is not exists.
*/
public function registerLocaleInternal($view)
{
$localeFilePath = $this->tryFindLocale();
if (YII_DEBUG && !$localeFilePath) {
throw new InvalidConfigException('Locale file "' . \Yii::$app->language . '" not exists!');
}
$manager = $view->getAssetManager();
$view->registerJsFile($manager->getAssetUrl($this, $this->locale), $this->jsOptions, 'moment-locale-' . $this->locale);
if ($this->setLocaleOnReady) {
$js = "moment().locale('" . $this->locale . "');";
$view->registerJs($js, View::POS_READY, 'moment-set-default-locale');
}
}
示例15: registerLocaleInternal
/**
* @param \yii\web\View $view
* @throws \yii\base\InvalidConfigException If file with the locale is not exists.
*/
public function registerLocaleInternal($view)
{
$localeFile = strtolower($this->locale) . '.js';
$localeFilePath = "{$this->sourcePath}/{$localeFile}";
if (YII_DEBUG && !file_exists($localeFilePath)) {
throw new InvalidConfigException('Locale file "' . $localeFilePath . '" not exists!');
}
$manager = $view->getAssetManager();
$view->registerJsFile($manager->getAssetUrl($this, $localeFile), $this->jsOptions, 'moment-locale-' . $this->locale);
if ($this->setLocaleOnReady) {
$js = "moment.locale('{$this->locale}');'";
$view->registerJs($js, View::POS_READY, 'moment-set-default-locale');
}
}