本文整理汇总了PHP中yii\helpers\Url类的典型用法代码示例。如果您正苦于以下问题:PHP Url类的具体用法?PHP Url怎么用?PHP Url使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Url类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
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();
}
示例2: run
/**
* Creates a new model.
* @return \yii\db\ActiveRecordInterface the model newly created
* @throws \Exception if there is any error when creating the model
*/
public function run()
{
if ($this->checkAccess) {
call_user_func($this->checkAccess, $this->id);
}
/**
* @var \yii\db\ActiveRecord $model
*/
$model = new $this->modelClass(['scenario' => $this->scenario]);
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
$model->on('afterInsert', array('backend\\eventListener\\SaveRelatedListener', 'saveRelated'));
$model->on('beforeValidate', array('backend\\eventListener\\SaveRelatedListener', 'beforeValidate'));
if ($model->validate()) {
$transaction = $model->getDb()->beginTransaction();
try {
$model->insert(false);
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollback();
throw $e;
}
}
if (!$model->hasErrors()) {
$response = Yii::$app->getResponse();
$response->setStatusCode(201);
$id = implode(',', array_values($model->getPrimaryKey(true)));
$response->getHeaders()->set('Location', Url::toRoute([$this->viewAction, 'id' => $id], true));
}
$model->refresh();
return $model;
}
示例3: actionIndex
public function actionIndex()
{
Url::remember('', 'actions-redirect');
$searchModel = Yii::createObject(UserSearch::className());
$dataProvider = $searchModel->search(Yii::$app->request->get());
return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]);
}
示例4: run
public function run()
{
$this->genButton = Html::a(Icon::show('edit') . Yii::t('app', 'Generate'), '#', ['class' => 'btn btn-success', 'id' => 'btn-generate']);
$parent_id = $this->model->main_category_id;
$owner_id = $this->model->id;
$this->addButton = Html::a(Icon::show('plus') . Yii::t('app', 'Add'), Url::toRoute(['/shop/backend-product/edit', 'parent_id' => $parent_id, 'owner_id' => $owner_id, 'returnUrl' => \app\backend\components\Helper::getReturnUrl()]), ['class' => 'btn btn-success', 'id' => 'btn-add']);
if (!empty($this->footer)) {
$this->footer = Html::tag('div', $this->addButton . ' ' . $this->genButton, ['class' => 'widget-footer']);
}
$this->object = Object::getForClass(get_class($this->model));
$rest_pg = (new Query())->select('id, name')->from(PropertyGroup::tableName())->where(['object_id' => $this->object->id])->orderBy('sort_order')->all();
$this->property_groups_to_add = [];
foreach ($rest_pg as $row) {
$this->property_groups_to_add[$row['id']] = $row['name'];
}
$optionGenerate = Json::decode($this->model->option_generate);
if (null === PropertyGroup::findOne($optionGenerate['group'])) {
$this->model->option_generate = $optionGenerate = null;
}
$groupModel = null;
if (isset($optionGenerate['group'])) {
$groupModel = PropertyGroup::findOne($optionGenerate['group']);
$properties = Property::getForGroupId($optionGenerate['group']);
} else {
$group_ids = array_keys($this->property_groups_to_add);
$group_id = array_shift($group_ids);
$groupModel = PropertyGroup::findOne($group_id);
$properties = Property::getForGroupId($group_id);
}
if (is_null($groupModel)) {
$groupModel = new PropertyGroup();
}
return $this->render($this->viewFile, ['model' => $this->model, 'form' => $this->form, 'groups' => $this->property_groups_to_add, 'groupModel' => $groupModel, 'properties' => $properties, 'optionGenerate' => $optionGenerate, 'footer' => $this->footer]);
}
示例5: afterUpdate
public function afterUpdate()
{
try {
if ($this->seoText->load(Yii::$app->request->post())) {
$this->seoText->setAttributes(['_image' => UploadedFile::getInstance($this->seoText, '_image')]);
// if(!$this->seoText->isEmpty()){
if ($this->seoText->save()) {
if ($this->seoText->_image) {
$old = $this->seoText->ogImage;
$photo = new Photo();
$photo->class = get_class($this->seoText);
$photo->item_id = $this->seoText->seotext_id;
$photo->image = $this->seoText->_image;
if ($photo->image && $photo->validate(['image'])) {
$photo->image = Image::upload($photo->image, 'photos', Photo::PHOTO_MAX_WIDTH);
if ($photo->image) {
if ($photo->save()) {
$old->delete();
} else {
@unlink(Yii::getAlias('@webroot') . str_replace(Url::base(true), '', $photo->image));
}
} else {
}
}
}
}
}
} catch (UnknownMethodException $e) {
}
}
示例6: init
public function init()
{
$paramsArr = ['offerUrl' => $this->offerUrl, 'textButton' => $this->textButton, 'type' => $this->type, 'columns' => $this->columns, 'model' => $this->model, 'showTotal' => $this->showTotal, 'showOptions' => $this->showOptions, 'showOffer' => $this->showOffer, 'showTruncate' => $this->showTruncate, 'currency' => $this->currency, 'otherFields' => $this->otherFields, 'currencyPosition' => $this->currencyPosition, 'showCountArrows' => $this->showCountArrows];
foreach ($paramsArr as $key => $value) {
if ($value === 'false') {
$this->{$key} = false;
}
}
$this->getView()->registerJs("pistol88.cart.elementsListWidgetParams = " . json_encode($paramsArr));
if ($this->type == NULL) {
$this->type = self::TYPE_FULL;
}
if ($this->offerUrl == NULL) {
$this->offerUrl = Url::toRoute(['/cart/default/index']);
}
if ($this->cart == NULL) {
$this->cart = yii::$app->cart;
}
if ($this->textButton == NULL) {
$this->textButton = yii::t('cart', 'Cart (<span class="pistol88-cart-price">{p}</span>)', ['c' => $this->cart->getCount(), 'p' => $this->cart->getCostFormatted()]);
}
if ($this->currency == NULL) {
$this->currency = yii::$app->cart->currency;
}
if ($this->currencyPosition == NULL) {
$this->currencyPosition = yii::$app->cart->currencyPosition;
}
\app\modules\cart\assets\WidgetAsset::register($this->getView());
return parent::init();
}
示例7: actionRss
public function actionRss()
{
/** @var News[] $news */
$news = News::find()->where(['status' => News::STATUS_PUBLIC])->orderBy('id DESC')->limit(50)->all();
$feed = new Feed();
$feed->title = 'YiiFeed';
$feed->link = Url::to('');
$feed->selfLink = Url::to(['news/rss'], true);
$feed->description = 'Yii news';
$feed->language = 'en';
$feed->setWebMaster('sam@rmcreative.ru', 'Alexander Makarov');
$feed->setManagingEditor('sam@rmcreative.ru', 'Alexander Makarov');
foreach ($news as $post) {
$item = new Item();
$item->title = $post->title;
$item->link = Url::to(['news/view', 'id' => $post->id], true);
$item->guid = Url::to(['news/view', 'id' => $post->id], true);
$item->description = HtmlPurifier::process(Markdown::process($post->text));
if (!empty($post->link)) {
$item->description .= Html::a(Html::encode($post->link), $post->link);
}
$item->pubDate = $post->created_at;
$item->setAuthor('noreply@yiifeed.com', 'YiiFeed');
$feed->addItem($item);
}
$feed->render();
}
示例8: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
// set titles
$this->setCreateTitle(Yii::t('kalibao', 'create_title'));
$this->setUpdateTitle(Yii::t('kalibao', 'update_title'));
// models
$models = $this->getModels();
// language
$language = $this->getLanguage();
// get drop down list methods
$dropDownList = $this->getDropDownList();
// upload config
$uploadConfig['main'] = $this->uploadConfig[(new \ReflectionClass($models['main']))->getName()];
// set items
$items = [];
if (!$models['main']->isNewRecord) {
$items[] = new SimpleValueField(['model' => $models['main'], 'attribute' => 'id', 'value' => $models['main']->id]);
}
$items[] = new InputField(['model' => $models['main'], 'attribute' => 'file', 'type' => 'activeFileInput', 'options' => ['maxlength' => true, 'class' => 'input-advanced-uploader', 'placeholder' => $models['main']->getAttributeLabel('file'), 'data-type-uploader' => $uploadConfig['main']['file']['type'], 'data-file-url' => $models['main']->file != '' ? $uploadConfig['main']['file']['baseUrl'] . '/' . $models['main']->file : '']]);
$items[] = new InputField(['model' => $models['main'], 'attribute' => 'media_type_id', 'type' => 'activeHiddenInput', 'options' => ['class' => 'form-control input-sm input-ajax-select', 'data-action' => Url::to(['advanced-drop-down-list', 'id' => 'media_type_i18n.title']), 'data-allow-clear' => 1, 'data-placeholder' => Yii::t('kalibao', 'input_select'), 'data-text' => !empty($models['main']->media_type_id) ? MediaTypeI18n::findOne(['media_type_id' => $models['main']->media_type_id, 'i18n_id' => $language])->title : '']]);
$items[] = new InputField(['model' => $models['i18n'], 'attribute' => 'title', 'type' => 'activeTextInput', 'options' => ['class' => 'form-control input-sm', 'maxlength' => true, 'placeholder' => $models['i18n']->getAttributeLabel('title')]]);
if (!$models['main']->isNewRecord) {
$items[] = new SimpleValueField(['model' => $models['main'], 'attribute' => 'created_at', 'value' => Yii::$app->formatter->asDatetime($models['main']->created_at, I18N::getDateFormat())]);
}
if (!$models['main']->isNewRecord) {
$items[] = new SimpleValueField(['model' => $models['main'], 'attribute' => 'updated_at', 'value' => Yii::$app->formatter->asDatetime($models['main']->updated_at, I18N::getDateFormat())]);
}
$this->setItems($items);
}
示例9: api_get
public function api_get($id_slug)
{
if (($text = $this->findText($id_slug)) === null) {
return $this->notFound($id_slug);
}
return LIVE_EDIT ? API::liveEdit($text['text'], Url::to(['/admin/text/a/edit/', 'id' => $text['text_id']])) : $text['text'];
}
示例10: run
public function run()
{
//Если данные по доставке закешированы просто рисуем их иначе делаем ajax запрос, чтобы заполнился кеш
if (\Yii::$app->v3toysSettings->isCurrentShippingCache) {
return $this->render($this->viewFile);
} else {
$js = \yii\helpers\Json::encode(['backend' => \yii\helpers\Url::to('/v3toys/cart/get-current-shipping')]);
$this->view->registerJs(<<<JS
(function(sx, \$, _)
{
sx.classes.GetShipping = sx.classes.Component.extend({
_onDomReady: function()
{
var self = this;
_.delay(function()
{
sx.ajax.preparePostQuery(self.get('backend')).execute();
}, 500);
}
});
new sx.classes.GetShipping({$js});
})(sx, sx.\$, sx._);
JS
);
}
}
示例11: getAssetUrl
/**
* @inheritdoc
*/
public function getAssetUrl($bundle, $asset)
{
if (($actualAsset = $this->resolveAsset($bundle, $asset)) !== false) {
if (strncmp($actualAsset, '@web/', 5) === 0) {
$asset = substr($actualAsset, 5);
$basePath = Yii::getAlias("@webroot");
$baseUrl = Yii::getAlias("@web");
} else {
$asset = Yii::getAlias($actualAsset);
$basePath = $this->basePath;
$baseUrl = $this->baseUrl;
}
} else {
$basePath = $bundle->basePath;
$baseUrl = $bundle->baseUrl;
}
if (!Url::isRelative($asset) || strncmp($asset, '/', 1) === 0) {
return $asset;
}
if ($this->appendTimestamp) {
foreach (['', '.gz'] as $appendExtension) {
if (($timestamp = @filemtime("{$basePath}/{$asset}{$appendExtension}")) > 0) {
return "{$baseUrl}/{$asset}?v={$timestamp}";
}
}
}
return "{$baseUrl}/{$asset}";
}
示例12: init
/**
* Initializes the widget.
*/
public function init()
{
parent::init();
if (empty($this->id)) {
$this->id = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId();
}
if (empty($this->name)) {
$this->name = $this->hasModel() ? Html::getInputName($this->model, $this->attribute) : $this->id;
}
if (empty($this->value) && $this->hasModel() && $this->model->hasAttribute($this->attribute)) {
$this->value = $this->model->getAttribute($this->attribute);
}
if (!$this->autoHeightEnable) {
if (empty($this->width)) {
$this->width = '100%';
}
if (empty($this->height)) {
$this->height = '350';
}
}
$options = ['id' => $this->id, 'style' => 'width:100%;height:350px'];
$this->options = array_merge($options, $this->options);
$jsOptions = ['serverUrl' => Url::to(['ueditor', 'type' => 'ueditor']), 'autoHeightEnable' => $this->autoHeightEnable, 'autoFloatEnable' => true, 'textarea' => $this->name];
$this->jsOptions = array_merge($jsOptions, $this->jsOptions);
}
示例13: up
public function up()
{
mb_internal_encoding("UTF-8");
$tableOptions = $this->db->driverName === 'mysql' ? 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB' : null;
$this->createTable('{{%wysiwyg}}', ['id' => Schema::primaryKey(), 'name' => Schema::string()->notNull(), 'class_name' => Schema::string()->notNull(), 'params' => Schema::text(), 'configuration_model' => Schema::string()], $tableOptions);
$this->insert('{{%wysiwyg}}', ['name' => 'Imperavi', 'class_name' => 'vova07\\imperavi\\Widget', 'params' => Json::encode(['settings' => ['replaceDivs' => false, 'minHeight' => 200, 'paragraphize' => false, 'pastePlainText' => true, 'buttonSource' => true, 'imageManagerJson' => Url::to(['/backend/dashboard/imperavi-images-get']), 'plugins' => ['table', 'fontsize', 'fontfamily', 'fontcolor', 'video', 'imagemanager'], 'replaceStyles' => [], 'replaceTags' => [], 'deniedTags' => [], 'removeEmpty' => [], 'imageUpload' => Url::to(['/backend/dashboard/imperavi-image-upload'])]]), 'configuration_model' => 'app\\modules\\core\\models\\WysiwygConfiguration\\Imperavi']);
}
示例14: init
public function init()
{
$this->controllerMap = ['elfinder' => ['class' => 'mihaildev\\elfinder\\Controller', 'access' => ['@'], 'disabledCommands' => ['netmount'], 'roots' => [['baseUrl' => $this->mediaUrl, 'basePath' => $this->mediaPath, 'path' => '', 'name' => 'Global']]]];
$this->modules = ['settings' => ['class' => 'plathir\\settings\\Module', 'modulename' => 'blog'], 'treemanager' => ['class' => '\\kartik\\tree\\Module', 'treeViewSettings' => ['nodeActions' => [\kartik\tree\Module::NODE_MANAGE => Url::to(['/blog/categorytree/manage']), \kartik\tree\Module::NODE_SAVE => Url::to(['/blog/categorytree/save']), \kartik\tree\Module::NODE_REMOVE => Url::to(['/blog/categorytree/remove']), \kartik\tree\Module::NODE_MOVE => Url::to(['/blog/categorytree/move'])], 'nodeView' => '/categorytree/_form']]];
parent::init();
// custom initialization code goes here
}
示例15: init
/**
* @inheritdoc
*/
public function init()
{
$groupId = Yii::$app->request->get('id');
$this->addItem(array('label' => Yii::t('AdminModule.setting', 'General'), 'url' => Url::toRoute(['/admin/authentication']), 'sortOrder' => 100, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'authentication' && Yii::$app->controller->action->id == 'index'));
$this->addItem(array('label' => Yii::t('AdminModule.setting', "LDAP"), 'url' => Url::toRoute(['/admin/authentication/authentication-ldap']), 'sortOrder' => 200, 'isActive' => Yii::$app->controller->module && Yii::$app->controller->module->id == 'admin' && Yii::$app->controller->id == 'authentication' && Yii::$app->controller->action->id == 'authentication-ldap'));
parent::init();
}