Kanika
Kanika

Reputation: 61

Yii2 change breadcrumb url

There are two user types in my admin application. If an admin is logged in, there should be a param in each url like this:

Home>>Property>> view property

Current url : www.example.com/property/index
Desired Url : www.example.com/property/index?agentid=5

How can I achieve this?

This param value will be dynamic and only for admin.

Upvotes: 3

Views: 676

Answers (1)

Yerke
Yerke

Reputation: 2235

In the top of your view file, (I consider view.php) You can use User::can() function to check for some admin/other permissions, and look at this example code to add param to link:

if (Yii::$app->user->can('admin')) {
    $this->params['breadcrumbs'][] = ['label' => 'Property', 'url' => ['index', 'agentid' => 5]];
} else {
    $this->params['breadcrumbs'][] = ['label' => 'Property', 'url' => ['index']];
}
$this->params['breadcrumbs'][] = $this->title;

It adds agentid=5 param if user has admin permission, and do not otherwise

Upvotes: 4

Related Questions