Yii dynamic title tag

I am doing a project in Yii framework now. i am concern about title tag and other meta tag which will be dynamic as well for SEO propose , The data for the tags will be fetched from database and displayed in the front-end.

What Should me my approach ?

Upvotes: 2

Views: 1848

Answers (2)

adamors
adamors

Reputation: 2656

You have basically two options here:

  1. Subclass CController, create a title property like @PeterM suggested and then inherit your controllers from this controller.
  2. Define an app parameter and echo that parameter in your layout. You can modify this from everywhere.

Upvotes: 2

user133408
user133408

Reputation:

In controller define:

public $title;

Then in your layout echo it into title tag.

<title><?= $this->title; ?></title>

In any action just assign $title and it will be displayed in layout title tag.

public function actionView()
{
    $this->title = 'My title fetched from DB'
}

Upvotes: 1

Related Questions