I am trying to pass the id of the user who is logged in as a parameter to the index.
<li class="active"><a href="<?php echo Yii::$app->request->baseUrl;?>/todo/index/"><span class="glyphicon glyphicon-home"></span> Home</a></li>
here i want to add the user id who is logged in:
what i have tried to fail:
<li class="active"><a href="<?php echo Yii::$app->request->baseUrl;?>/todo/index/. Yii::$app->user->identity->username ."><span class="glyphicon glyphicon-home"></span> Home</a></li>
You can do like this
<li class="active">
<a href="<?php echo Yii::$app->request->baseUrl.'/todo/index/'.Yii::$app->user->identity->username;?>">
<span class="glyphicon glyphicon-home"></span> Home
</a>
</li>
Try this:
<?= Html::a('<i class="glyphicon glyphicon-home">Home', Url::to(['todo/index', 'user_id' => Yii::$app->user->id]), ['class' => 'btn btn-default']) ?>
Accepted answer is great but you should use:
<a href="<?= Yii::$app->urlManager->createAbsoluteUrl(array("todo/index", "uname" => Yii::$app->user->identity->username)); ?>">
It is not a good practice too write the SEF url directly. You should format it using rules.