Created
December 3, 2018 12:39
-
-
Save fedek6/c15b6ef07c134c9ab1cd60535a365c33 to your computer and use it in GitHub Desktop.
Prepend application name to site title in Yii2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Extension of base controller. | |
* Add additional controller functions and vars here. | |
*/ | |
namespace app\components; | |
use Yii; | |
class Controller extends \yii\web\Controller | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function init() | |
{ | |
// Prepend application name to site title | |
$this->view->on('afterRender', function($event) | |
{ | |
if(!empty(Yii::$app->view->title)) | |
{ | |
Yii::$app->view->title = Yii::$app->name . Yii::$app->params['titleSeparator'] . Yii::$app->view->title; | |
} | |
else | |
{ | |
Yii::$app->view->title = Yii::$app->name; | |
} | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* @var $this yii\web\View */ | |
$this->title = 'test'; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
'adminEmail' => '[email protected]', | |
'titleSeparator' => ' – ', | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\controllers; | |
use Yii; | |
use app\components\Controller; | |
class SiteController extends Controller | |
{ | |
/** | |
* Displays homepage. | |
* | |
* @return string | |
*/ | |
public function actionIndex() | |
{ | |
return $this->render('index'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment