本文整理汇总了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;
}
示例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 . ");");
}
}
示例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;
}
示例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);
}
}
示例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])]);
}
示例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;
}
示例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]);
}
}
示例8: getUrl
public function getUrl($url)
{
if ($url === "") {
$url = "/";
}
return Url::toRoute($url);
}
示例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));
}
示例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);
}
示例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]);
}
示例12: getUrl
public function getUrl()
{
if ($this->_ajaxUrl === null) {
$this->_ajaxUrl = Url::toRoute($this->url);
}
return $this->_ajaxUrl;
}
示例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]);
}
示例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]);
}
示例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]);
});
}')]])]);
}