(注:己yii2.0高级应用为例)
面包屑在布局里定义好之后,在视图中直接使即可,但默是使用英文。
一、布局中定义面包屑
backend/views/layout/main.php:
use backend\assets\AppAsset;
use yii\widgets\Breadcrumbs; AppAsset::register($this); //省略代码
.....
<?= Breadcrumbs::widget([
//'homeLink'=>['label' => '主 页','url' => Yii::$app->homeUrl],
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
])
?> 视图中如何使用?
use yii\helpers\Html;
use backend\assets\AppAsset;
use api\widgets\Alert;
/* @var $this yii\web\View */ $this->title= '代理系统-后台首页';
//$this->minzi= 'Extra Pages';
$this->params['breadcrumbs'][] = '应用结构';
$this->params['breadcrumbs'][] = '视图';
AppAsset::register($this); 二、配置开启支持多语言
以下几种,选择一种即可(若发布服务器,最后两种可选)
frontend/config/main-local.php:
if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
// 开启yii-debug-toolbar
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module'; $config['bootstrap'][] = 'gii';
$config['modules']['gii'] = 'yii\gii\Module';
// $config['language'] = 'zh-CN';<span style="font-family: Arial, Helvetica, sans-serif;">//增加此行,默认使用中文</span> } frontend/config/main.php:
return [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'language' =>'zh-CN', //增加此行,默认使用中文 common/config/main.php
return [
'language' =>'zh-CN',//默认使用中文
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],