I am looking for yii2 beadcrumb code
I have layout page in twig want to add breadcrumb there and want to update it according to pages for example
Dashboard/Employees/Add Employee
Dashboard/Employee/Edit Employee
Dashboard and employee will be clickable
I got very less information on yii2 breadcrumbs on internet.
In your main layout use:
<?=
Breadcrumbs::widget([
'homeLink' => [
'label' => Yii::t('yii', 'Dashboard'),
'url' => Yii::$app->homeUrl,
],
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
])
?>
And in your view:
$this->title = 'Add Employee';
$this->params['breadcrumbs'][] = ['label' => 'Employees', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
This will generate the following breadcrumbs:
Dashboard / Employees / Add Employee
In your layout-
//use yii\widgets\Breadcrumbs;
<?=
Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
])
?>
In your view-
$this->title = 'Example';
$this->params['breadcrumbs'][] = $this->title;
Hope it will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With