当前位置: 首页>>代码示例>>PHP>>正文


PHP Url::toRoute方法代码示例

本文整理汇总了PHP中yii\helpers\Url::toRoute方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::toRoute方法的具体用法?PHP Url::toRoute怎么用?PHP Url::toRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\helpers\Url的用法示例。


在下文中一共展示了Url::toRoute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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;
 }
开发者ID:portalsway2,项目名称:APEDevices,代码行数:36,代码来源:CreateAction.php

示例2: run

 public function run()
 {
     if (empty($this->name) && (!empty($this->model) && !empty($this->attribute))) {
         $this->name = Html::getInputName($this->model, $this->attribute);
     }
     if (empty($this->url)) {
         $this->url = Url::toRoute(['site/upload']);
     }
     $options = ['url' => $this->url, 'paramName' => $this->name, 'params' => []];
     if (Yii::$app->request->enableCsrfValidation) {
         $options['params'][Yii::$app->request->csrfParam] = Yii::$app->request->getCsrfToken();
     }
     if (!empty($this->message)) {
         $message = Html::tag('div', $this->message, $this->messageOptions);
     } else {
         $message = '';
     }
     $this->htmlOptions['id'] = $this->id;
     $this->options = ArrayHelper::merge($this->options, $options);
     echo Html::tag('div', $message, $this->htmlOptions);
     $this->registerAssets();
     $this->createDropzone();
     foreach ($this->eventHandlers as $event => $handler) {
         $handler = new \yii\web\JsExpression($handler);
         $this->getView()->registerJs($this->dropzoneName . ".on('{$event}', {$handler})");
     }
     $this->addFiles($this->storedFiles);
     $this->decrementMaxFiles(count($this->storedFiles));
     if ($this->sortable) {
         $options = Json::encode($this->sortableOptions);
         $this->getView()->registerJs("jQuery('#{$this->id}').sortable(" . $options . ");");
     }
 }
开发者ID:rumes,项目名称:yii2-dropzone,代码行数:33,代码来源:DropZone.php

示例3: 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(), '');
     $folder = \Yii::$app->getRequest()->getQueryParam('folder');
     $isPrivate = \Yii::$app->getRequest()->getQueryParam('is_private');
     $model->setAttribute('folder', $folder);
     $storageId = Yii::$app->get('settings')->get('File.storageId');
     /** @var StorageInterface $storage */
     $storage = $this->controller->module->getStorage($storageId);
     $storage->upload($model, 'file', $isPrivate);
     $model->on('afterInsert', array('backend\\eventListener\\SaveRelatedListener', 'saveRelated'));
     $model->on('beforeValidate', array('backend\\eventListener\\SaveRelatedListener', 'beforeValidate'));
     $model->on('afterInsert', array('backend\\modules\\file\\eventListener\\ResizeLogoFIle', 'createSpecialLogo'));
     $model->on('afterUpdate', array('backend\\modules\\file\\eventListener\\ResizeLogoFIle', 'createSpecialLogo'));
     $model->save();
     $model->afterFind();
     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));
     }
     return $model;
 }
开发者ID:portalsway2,项目名称:APEDevices,代码行数:36,代码来源:CreateAction.php

示例4: run

 public function run()
 {
     $this->controller->layout = empty($this->controller->updateLayoutFile) ? $this->layoutFile : $this->controller->updateLayoutFile;
     $id = Yii::$app->request->get($this->idAttribute, 0);
     if ($id == 0) {
         $this->controller->{$this->returnFailMethod}($this->returnBadParamMsg, [], $this->extraReturnParam);
     }
     $model = new $this->modelClass();
     $model = $model::findOne($id);
     $model->setScenario($this->scenarioName);
     if (!empty($model)) {
         if (!empty(Yii::$app->request->post($model->formName()))) {
             if ($model->load(Yii::$app->request->post()) && $model->validate()) {
                 $model->save();
                 $this->controller->{$this->returnSuccessMethod}($this->returnSuccessMsg, Url::toRoute($this->redirectRoute), $this->extraReturnParam);
             } else {
                 $this->controller->{$this->returnFailMethod}($this->returnFailMsg, $model->getErrors(), $this->extraReturnParam);
             }
         } else {
             return $this->controller->render($this->viewFile, ['model' => $model]);
         }
     } else {
         $this->controller->{$this->returnFailMethod}($this->returnObjectNotExistMsg);
     }
 }
开发者ID:tksoftcn,项目名称:yii2-enhance,代码行数:25,代码来源:ViewAction.php

示例5: actionSave

 public function actionSave($languageId = null, $categoryId = null)
 {
     if (!empty($categoryId)) {
         $category = Category::findOne($categoryId);
         $category_translation = CategoryTranslation::find()->where(['category_id' => $categoryId, 'language_id' => $languageId])->one();
         if (empty($category_translation)) {
             $category_translation = new CategoryTranslation();
         }
     } else {
         $category = new Category();
         $category_translation = new CategoryTranslation();
     }
     if (Yii::$app->request->isPost) {
         $category->load(Yii::$app->request->post());
         $category_translation->load(Yii::$app->request->post());
         if ($category->validate() && $category_translation->validate()) {
             $category->save();
             $category_translation->category_id = $category->id;
             $category_translation->language_id = $languageId;
             $category_translation->save();
             Yii::$app->getSession()->setFlash('success', 'Data were successfully modified.');
             return $this->redirect(Url::toRoute('/articles/category'));
         } else {
             Yii::$app->getSession()->setFlash('danger', 'Failed to change the record.');
         }
     }
     return $this->render('edit', ['category' => $category, 'category_translation' => $category_translation, 'categories' => Category::find()->with('translations')->all(), 'selectedLanguage' => Language::findOne($languageId), 'languages' => Language::findAll(['active' => true])]);
 }
开发者ID:black-lamp,项目名称:yii2-articles,代码行数:28,代码来源:CategoryController.php

示例6: getNavBar

    protected static function getNavBar($items, $cur_url, $class = 'sidebar')
    {
        $count = count($items);
        $i = 0;
        $line = '<ul class="' . $class . '-menu">';
        foreach ($items as $item) {
            $icon_class = $item['icon_class'];
            if (isset($item['url']) && $item['url'] != '') {
                $active = self::checkSelected($item['url'], $cur_url);
                $url = $item['url'];
                $url = Url::toRoute($url);
                $line = $line . '<li class="' . $active . '">
								<a href="' . $url . '"><span class="fa ' . $icon_class . '"></span>' . $item['label'] . '</a>
							</li>';
            } else {
                $active = self::checkSelected($item['items'], $cur_url);
                $line = $line . '<li class="treeview ' . $active . '">
								<a href="#">
								<i class="fa ' . $icon_class . '"></i> <span>' . $item['label'] . '</span>
								<i class="fa fa-angle-left pull-right"></i>
							</a>';
                $line = $line . self::getNavBar($item['items'], $cur_url, 'treeview');
            }
            $line = $line . '</li>';
            $i++;
            if ($i == $count) {
                $line = $line . '</ul>';
            }
        }
        return $line;
    }
开发者ID:esoftkz,项目名称:yii2-adminlte-asset,代码行数:31,代码来源:Drmenu.php

示例7: actionTixian

 /**
  * 提现操作
  * @return type
  */
 public function actionTixian()
 {
     $model = new CashForm();
     if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
         #调有存储过程冻结资金并生成订单
         try {
             $addip = \Yii::$app->request->userIP;
             $user_id = \Yii::$app->user->getId();
             $money = $model->money;
             $conn = \Yii::$app->db;
             $command = $conn->createCommand('call p_apply_Cash(:in_p_user_id,:money,:in_addip,@out_status,@out_remark)');
             $command->bindParam(":in_p_user_id", $user_id, PDO::PARAM_INT);
             $command->bindParam(":money", $money, PDO::PARAM_STR);
             $command->bindParam(":in_addip", $addip, PDO::PARAM_STR, 50);
             $command->execute();
             $fit = $conn->createCommand("select @out_status as status,@out_remark as remark")->queryOne();
         } catch (Exception $e) {
             $fit = ['remark' => '系统繁忙,暂时无法处理', 'status' => 0];
         }
         if ($fit['status'] == 0) {
             $msgtitle = '操作失败';
         } else {
             $msgtitle = '操作成功';
         }
         $notices = array('type' => 3, 'msgtitle' => $msgtitle, 'message' => $fit['remark'], 'backurl' => Url::toRoute('/member/account/tixian'), 'backtitle' => '返回', 'tourl' => Url::toRoute('/member/account/index/index'), 'totitle' => '会员中心');
         \Yii::$app->getSession()->setFlash('wechat_fail', array($notices));
         $this->redirect(Url::toRoute('/public/notices'));
         \Yii::$app->end();
     } else {
         return $this->render('account_tixian', ['model' => $model]);
     }
 }
开发者ID:uqiauto,项目名称:wxzuan,代码行数:36,代码来源:AccountController.php

示例8: getUrl

 public function getUrl($url)
 {
     if ($url === "") {
         $url = "/";
     }
     return Url::toRoute($url);
 }
开发者ID:jcheron,项目名称:phalcon-jquery,代码行数:7,代码来源:JsUtils.php

示例9: run

 /**
  * Updates an existing model or creates a new one if $id is null.
  * @param string $id the primary key of the model.
  * @return \yii\db\ActiveRecordInterface the model being updated
  * @throws ServerErrorHttpException if there is any error when updating the model
  */
 public function run($id, $enable = null)
 {
     $model = $this->findModel($id);
     if ($this->checkAccess) {
         call_user_func($this->checkAccess, $this->id, $model);
     }
     if ($enable !== null) {
         $enable = (bool) $enable;
     }
     /** @var \nineinchnick\audit\behaviors\TrackableBehavior $trackable */
     if (($trackable = $model->getBehavior('trackable')) !== null) {
         $trackable->beginChangeset();
     }
     $model->toggle($enable);
     if ($trackable !== null) {
         $trackable->endChangeset();
     }
     $response = Yii::$app->getResponse();
     $response->setStatusCode($enable ? 205 : 204);
     if ($enable) {
         $message = Yii::t('app', '<strong>Success!</strong> Record has been restored.');
     } else {
         $message = Yii::t('app', '<strong>Success!</strong> Record has been disabled.');
     }
     $this->setFlash('success', $message);
     $id = $this->exportKey($model->getPrimaryKey(true));
     $response->getHeaders()->set('Location', Url::toRoute([$this->viewAction, 'id' => $id], true));
 }
开发者ID:netis-pl,项目名称:yii2-crud,代码行数:34,代码来源:ToggleAction.php

示例10: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $script = '
     $(document).ready(function(){
         function hideFirstLast() {
             $(\'.sort-up, .sort-down\').show();
             $(\'.sort-up\').first().hide();
             $(\'.sort-down\').last().hide();
         }
         function refresh() {
             $(\'#' . $this->grid->id . '\').yiiGridView("applyFilter");
             hideFirstLast();
         }
         $(\'.sort-up\').on(\'click\', function(){
             var id = $(this).parent().parent().attr(\'data-key\');
             $.post("' . Url::toRoute(['swap']) . '?id="+id+"&dir=up").always(refresh);
             return false;
         });
         $(\'.sort-down\').on(\'click\' ,function(){
             var id = $(this).parent().parent().attr(\'data-key\');
             $.post("' . Url::toRoute(['swap']) . '?id="+id+"&dir=down").always(refresh);
             return false;
         });
         hideFirstLast();
     });';
     $this->grid->getView()->registerJs($script);
 }
开发者ID:alisherdavronov,项目名称:yii2-grid-sort-column-enh,代码行数:31,代码来源:SortColumn.php

示例11: actionSignup

 /**
  * Регистрация
  * @return array|string|Response
  */
 public function actionSignup()
 {
     $user = new models\User(['scenario' => 'signup']);
     $profile = new models\Profile(['scenario' => 'signup']);
     if ($user->load(Yii::$app->request->post()) && $profile->load(Yii::$app->request->post())) {
         if ($user->validate() && $profile->validate()) {
             $user->populateRelation('profile', $profile);
             if ($user->save(false)) {
                 if ($this->module->requireEmailConfirmation === true) {
                     Yii::$app->consoleRunner->run('users/control/send-email ' . $user->email . ' signup "' . Yii::t('users', 'SUBJECT_SIGNUP') . '"');
                     Yii::$app->session->setFlash('success', Yii::t('users', 'SUCCESS_SIGNUP_WITHOUT_LOGIN', ['url' => Url::toRoute('resend')]));
                 } else {
                     Yii::$app->user->login($user);
                     Yii::$app->session->setFlash('success', Yii::t('users', 'SUCCESS_SIGNUP_WITH_LOGIN'));
                 }
                 return $this->redirect(['login']);
             } else {
                 Yii::$app->session->setFlash('danger', Yii::t('users', 'FAIL_SIGNUP'));
                 return $this->refresh();
             }
         } else {
             if (Yii::$app->request->isAjax) {
                 Yii::$app->response->format = Response::FORMAT_JSON;
                 return ActiveForm::validate($user);
             }
         }
     }
     return $this->render('signup', ['user' => $user, 'profile' => $profile]);
 }
开发者ID:nepster-web,项目名称:yii2-module-users,代码行数:33,代码来源:GuestController.php

示例12: getUrl

 public function getUrl()
 {
     if ($this->_ajaxUrl === null) {
         $this->_ajaxUrl = Url::toRoute($this->url);
     }
     return $this->_ajaxUrl;
 }
开发者ID:keygenqt,项目名称:yii2-image-ajax,代码行数:7,代码来源:ImageAjax.php

示例13: actionBroker

 public function actionBroker()
 {
     if (Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = Broker::findOne(Yii::$app->user->identity->getId());
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate() && $model->getDirtyAttributes()) {
             $mes = [];
             foreach ($model->getDirtyAttributes() as $k => $v) {
                 if ($k == 'name' && $model->type_id == 1) {
                     $mes[$k] = [Yii::t('app', 'Full name'), $model->name];
                 } else {
                     $mes[$k] = [$model->getAttributeLabel($k), $model->{$k}];
                 }
             }
             $message = "";
             foreach ($mes as $m) {
                 $message .= "<p><b>" . $m[0] . ":</b> " . $m[1] . "</p>";
             }
             $new = Broker::findOne($model->user_id);
             if ($message) {
                 $new->edit = $message;
                 Yii::$app->session->setFlash('success', Yii::t('app', 'Sent admin to verify.'));
             } else {
                 $new->edit = '';
             }
             $new->save();
             return $this->redirect(Url::toRoute('personal/index'));
         }
     }
     return $this->render('broker', ['model' => $model]);
 }
开发者ID:dench,项目名称:resistor,代码行数:33,代码来源:PersonalController.php

示例14: actionEdit

 /**
  * Updates an existing Discount model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionEdit($id = false)
 {
     $model = new Discount();
     if ($id !== false) {
         $model = Discount::findOne($id);
     } else {
         $model->loadDefaultValues();
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->save()) {
             Yii::$app->session->setFlash('info', Yii::t('app', 'Object saved'));
             $returnUrl = Yii::$app->request->get('returnUrl', ['/shop/backend-discount/index']);
             switch (Yii::$app->request->post('action', 'save')) {
                 case 'next':
                     return $this->redirect(['/shop/backend-discount/edit', 'returnUrl' => $returnUrl]);
                 case 'back':
                     return $this->redirect($returnUrl);
                 default:
                     return $this->redirect(Url::toRoute(['/shop/backend-discount/edit', 'id' => $model->id, 'returnUrl' => $returnUrl]));
             }
         }
     }
     if (Yii::$app->request->isPost && !$model->isNewRecord) {
         foreach ($model::getTypeObjects() as $object) {
             $object->discount_id = $model->id;
             if ($object->load(Yii::$app->request->post()) && $object->validate()) {
                 $object->save();
             }
         }
     }
     return $this->render('form', ['model' => $model]);
 }
开发者ID:tqsq2005,项目名称:dotplant2,代码行数:38,代码来源:BackendDiscountController.php

示例15: init

 public function init()
 {
     parent::init();
     $request = AH::merge(['wrapper' => 'results', 'term' => 'search:term'], $this->uses);
     $requests = [];
     $back_request = [];
     foreach ($request as $k => $v) {
         if ($k === 'term') {
             $requests[] = $v;
         } elseif (is_array($v)) {
             $requests[] = "{$k}:" . json_encode($v);
             $back_request[] = "{$k}:" . json_encode($v);
         } else {
             $requests[] = "{$k}:'{$v}'";
             $back_request[] = "{$k}:'{$v}'";
         }
     }
     \Yii::configure($this, ['format' => 'html', 'filterInputOptions' => ['id' => 'id'], 'filter' => Select2::widget(['attribute' => 'id', 'model' => $this->grid->filterModel, 'url' => Url::toRoute(['list']), 'settings' => ['ajax' => ['data' => new JsExpression('function(term,page) { return {' . implode(', ', $requests) . '}; }')], 'initSelection' => new JsExpression('function (elem, callback) {
                     var id=$(elem).val();
                     $.ajax("' . Url::toRoute(['list']) . '?id=" + id, {
                         dataType: "json",
                         data : {' . implode(', ', $back_request) . '}
                     }).done(function(data) {
                         callback(data.results[0]);
                     });
                 }')]])]);
 }
开发者ID:hiqdev,项目名称:hipanel-core,代码行数:27,代码来源:CurrentColumn.php


注:本文中的yii\helpers\Url::toRoute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。