You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB

7 years ago
<?php
namespace frontend\bootstrap;
use core\entities\Settings;
use core\helpers\LanguageHelper;
3 years ago
use Yii;
7 years ago
use yii\base\BootstrapInterface;
use yii\helpers\ArrayHelper;
use yii\widgets\Breadcrumbs;
class SetUp implements BootstrapInterface
{
public function bootstrap($app): void
{
3 years ago
$container = Yii::$container;
7 years ago
$container->set(Breadcrumbs::class, function ($container, $params, $args) {
return new Breadcrumbs(ArrayHelper::merge([
'homeLink' => [
//'label' => '<span class="fa fa-home"></span>',
3 years ago
'label' => Yii::t('post', 'Home'),
7 years ago
'encode' => false,
3 years ago
'url' => Yii::$app->homeUrl,
7 years ago
],
], $args));
});
7 years ago
// Load settings
$settings = Settings::find()->with('translations')->andWhere(['active' => 1])->all();
$settings_array = $settings ? ArrayHelper::map($settings, 'key', function ($el) {
3 years ago
return $el->translation->value ?? '';
}, 'section') : [];
$app->params['settings'] = $settings_array;
7 years ago
// Add finish UrlRules
$app->getUrlManager()->addRules([
'<_c:[\w\-]+>' => '<_c>/index',
'<_c:[\w\-]+>/<id:\d+>' => '<_c>/view',
'<_c:[\w\-]+>/<_a:[\w-]+>' => '<_c>/<_a>',
'<_c:[\w\-]+>/<id:\d+>/<_a:[\w\-]+>' => '<_c>/<_a>',
]);
// redefine home url
3 years ago
Yii::$app->homeUrl = LanguageHelper::addLangToUrl(Yii::$app->homeUrl);
7 years ago
}
}