D
D
Dastan2015-11-03 14:39:50
Yii
Dastan, 2015-11-03 14:39:50

How to change the format of generated links using Url::to in Yii2?

I do sending mail at registration.
The site works like this: the frontend is in angular, that is, Ajax, and the backend is Yii2.
Here is the method code:

public function getUrl()
    {
        switch ($this->type) {
            case self::TYPE_CONFIRMATION:
                $route = '/#/api/registration/confirm';
                break;
            case self::TYPE_RECOVERY:
                $route = '/#/api/recovery/reset';
                break;
            case self::TYPE_CONFIRM_NEW_EMAIL:
            case self::TYPE_CONFIRM_OLD_EMAIL:
                $route = '/#/api/settings/confirm';
                break;
            default:
                throw new \RuntimeException;
        }

        return Url::to([$route, 'id' => $this->user_id, 'code' => $this->code], true);
    }

At the beginning, a letter came in the following format:
newne/user/confirm/3/JFQFZNy5T8Ff0t9dprgYWYPm5aJ23TA5
After I changed /user/confirm to /#/api/registration/confirm,
the URL changed to this:
newne/#/api/registration/confirm? id=14&code=VcLlwl...
And the angularJS routes in the format "/route/:param1/:param2" and even more beautiful))
Based on what law did Yii build the URL differently?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2015-11-04
@dastiw1

"The site is in angular, that is, ajax" - what does yii have to do with it? Did you blind them? Angular frontend, YII backend?
"Based on what law did Yii build a URL to a friend?" - dig urlmanager in config and read manuals www.yiiframework.com/doc-2.0/yii-helpers-url.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question