在yii2中将标题页设置为h1

sbtkgmzw  于 2022-11-09  发布在  其他
关注(0)|答案(2)|浏览(127)

在yii2中设置标题页为h1?
在视图中:

$this->title = 'title' ;

和源代码:

<title>title</title>
ogq8wdun

ogq8wdun1#

在视图中,该值被分配给$this-〉title,以便在head中使用,并且如果在用户视图中有用

<?php

   $this->title = $model->id;

?>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My Title  </title> <!-- this is for SEO -->
    ...
</head>
<body>
    <h1><?= $this->title ?> </h1> <!-- this is for user view -->
zy1mlcev

zy1mlcev2#

设置title变量。示例:

$this->title = $model->id;  //Set title

然后在视图或布局文件中使用title变量。例如:

Html::encode($this->title)

此处

<?php
      # PHP code...
    use yii\helpers\Html;
    use app\assets\AppAsset;
    AppAsset::register($this);  //register an asset bundle
  ?>

<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <?= Html::csrfMetaTags() ?>  <!-- // CSRF -->

    <title><?= Html::encode($this->title) ?></title> <!-- for Page and Seo -->
    <?php $this->head() ?>

</head>
<body>
<?php $this->beginBody() ?>    
    <div class="wrap">
         <?= $content ?>  <!-- # view file:<h1> or...  #Html::encode($this->title)--> 
    </div>

<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>

相关问题