Come to private home URL

Hi

when i connect with a user and i want to come to http://root/index.php

it return to first public home page and not to the private home page (profile)

Thank

Try this


if ($model->login()) {

    return $this->redirect(['//user/view', 'id' => Yii::$app->user->id]); // OR

    // return $this->redirect(['//user/view', 'id' => Yii::$app->user->identity->id]);

}

thank for support but my problem is when i connect and i want to come to user home (breadcrumbs ex home- xxx - xxx)

when i click on home it come to public home before my connection! i want to stay on the first page when i connect!

Do you want to provide a private HOME page for each logged in user instead of the global HOME page for the guest users?

yes it is!

The following solution is not fully tested, but you can try it.

You can overwrite yii\webApplication::homeUrl (http://www.yiiframework.com/doc-2.0/yii-web-application.html#$homeUrl-detail) in an event handler of the Application event EVENT_BEFORE_ACTION (http://www.yiiframework.com/doc-2.0/guide-structure-applications.html#beforeAction).

Add the following in your ‘web.php’ configuration file:




$config = [

    ...

    'on beforeAction' => function($event) {

        if (!Yii::$app->user->isGuest) {

            Yii::$app->homeUrl = ['/profile/view', 'id' => Yii::$app->user->id];

        }

    },

];



Don’t forget to adjust the url for the user profile page. :)

it is coming but the problem now is the fact with my example /site/index

it put the other parts of my interface (private home) but the body, it call the index of /home/index

I’m sorry, but I don’t understand what you are trying to do.

what i want to say, it is ok but :

to display iit return this the part when user is connected (bold) (main.php)

<div class="wrap">

<?php if (Yii::$app->controller->action->id === ‘login’ || Yii::$app->controller->action->id === ‘register’ || Yii::$app->controller->action->id === ‘reset’){ ?>

<?= $this->render(‘login-layout.php’, [‘content’=> $content]) ?>

<?php } else if (Yii::$app->controller->action->id=== ‘error’){ ?> <?= $this->render(‘content.php’, [‘content’=> $content]) ?>

<?php }else { if(Yii::$app->user->isGuest) return $this->goHome(); else { ?>

[b]

<?= $this->render(‘header.php’,[‘baseUrl’=> $baseUrl]) ?>

<?= $this->render(‘leftmenu.php’, [‘baseUrl’=> $baseUrl]) ?>

<?= $this->render(‘content.php’, [‘content’=> $content, ]) ?>

<?= $this->render(‘footer.php’,[‘baseUrl’=> $baseUrl]) ?>

<?= $this->render(‘rightside.php’,[‘baseUrl’=> $baseUrl]) ?>[/b]

<?php } } ?>

<div class=‘control-sidebar-bg’></div>

</div>

the other page return the right information when user is connected but only the content.php return index of my index in my view /home

but i specify /site/index in web.php

I still don’t understand what you mean. What do you mean by “my view /home” and “/site/index”?

If you have followed the solution I suggested, then Yii::$app->homeUrl will be changed to the user specific HOME when he/she is logged in. If you want to access the original home, you have to be a guest or have to use an explicit link to that page.

It is impossible to understand what you are trying to say…

But, I know this:

/site/index means the index action of the site controller.

No matter what $homeURL is set to.