M
M
Maxim2018-06-21 15:18:52
Yii
Maxim, 2018-06-21 15:18:52

Yii how to link back?

Hello everyone) There is such a task. You need to make a link to the level up. The framework has Yii::$app->request->referrer. However, it throws the user back to the previous page. And if I need to go back "along the trees" like in bread crumbs... Maybe I can extract from there...
For example. Home -> Events ->View
The back button will first return to the events and then to the main page.
Now I made such a widget. How can it be improved?

class BackUrl extends Widget
{

    public $url;

    public function init()
    {
        parent::init();

        if ($this->url === null) {
            if (Yii::$app->request->referrer){
                $this->url = Yii::$app->request->referrer;
            } else {
                $this->url = ['index'];
            }
        }
    }

    public function run()
    {
        return Html::tag('div', Html::a('<i class="fa fa-chevron-left"></i> Назад', $this->url),['class'=>'back-url']);
    }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Bukharev, 2018-06-21
@myks92

This widget should work in tandem with the breadcrumb display widget, namely, it should fire which url is currently active, and if it has a parent, then display a link to the parent, while analyzing the hierarchy of breadcrumbs. Session, cookies, Yii::$app->request->referrer, Url::remember() are not needed here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question