php - 使用 Yii 框架时标题和元标记的顺序

标签 php html model-view-controller yii seo

您好,我正在研究 Yii 1x 框架。我使用了提到的方法 http://www.apurbadebnath.com/blog/yii-how-to-set-up-page-title-and-meta-description-from-yii-controller/ 在以下链接中。

我面临的问题是我 View 中的标题标 checkout 现在我使用 Yii Controller 注册的元标签之后。从 SEO 的角度来看,在元标记(desc 和关键字)之前获得标题很重要。请问有没有办法解决以上问题。

提前致谢。

最佳答案

这是设计使然。来自文档:

Registers a meta tag that will be inserted in the head section (right before the title element) of the resulting page.

我建议在父 Controller 中将所有必要的元参数声明为变量,并在子 Controller 中适本地设置它们。

$this->meta_param_1 = 'test';
$this->meta_param_2 = 'test';

然后像这样在您的布局中设置它们:

<title><?php echo CHtml::encode($this->pageTitle); ?></title>
<meta name="meta_param_1" content="<?php echo CHtml::encode($this->meta_param_1); ?>" />
<meta name="meta_param_2" content="<?php echo CHtml::encode($this->meta_param_2); ?>" />

关于php - 使用 Yii 框架时标题和元标记的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33095653/

相关文章:

html - css 输入和按钮放大

php - 在 View 中或仅在 Controller 中检索模型数据是否正确?

ios - 不同组件如何在iOS的MVVM中通信

PHPExcel - 锁定正在查看的文件

javascript - 高分子高分子微致错

javascript - 对网页进行实时更新时跟踪更改的方法

html - 当窗口大小减小时,使用媒体查询来增加我的主体容器的高度大小时,它将不起作用。

css - CSS 文件中定义的图像不适用于 spring mvc

PHP获取类实例的变量名称?

php - 表单实体 : add an extra option