dpb75177
2017-08-21 07:05
浏览 169
已采纳

在yii2中将标题页设置为h1

set title page to h1 in yii2?

in view :

$this->title = 'title' ;

and source code :

<title>title</title>

图片转代码服务由CSDN问答提供 功能建议

在yii2中将标题页设置为h1?

在视图中:

  $ this-&gt; title ='title'; 
   
 
 

和源代码: <前> &lt; title&gt; title&lt; / title&gt;

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dqxyh48864 2017-08-21 07:17
    已采纳

    In view the value is assigned to $this->title for the use in head and if useful in user view

    <?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 -->
    
    打赏 评论
  • doufud21086 2018-12-13 11:41

    Setting the title variable. example:

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

    Then use the title variable in the view or layout file. example:

    Html::encode($this->title)
    

    here

    <?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() ?>
    
    打赏 评论

相关推荐 更多相似问题