Skip to content

Advanced usage: generate links on tags #9

Open
@antonkomarev

Description

@antonkomarev

Here is how I'm using tags without SluggableBehavior.

In application config:

'components' => [
    'urlManager' => [
        'class' => 'yii\web\UrlManager',
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules'=> [
            ['pattern'=>'tag/<tag>', 'route'=>'tag/view'],
        ]
    ],
]

In view file:

<?php foreach ($model->getTagNames(true) as $tag) : ?>
    <?= Html::a($tag, ['/tag/view', 'tag' => $tag]) ?>
<?php endforeach ?>

If we have a tag tag with whitespace we will have a generated link:
/tag/tag+with+whitespace

This link will call TagController:actionView() method and bypass tag parameter in Yii::$app->request->queryParams array.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions