cakephp:如何为每个页面制作独特的标题和元标记?

时间:2015-01-01 12:25:13

标签: cakephp

我在cakephp 2.2中制作了一个项目

它使用default.ctp布局

<title>, <meta> are harde coded 

因此,我网站的页面具有相同的标题和元素

我的目标(对于SEO)是为每个页面制作标题和元素(每个控制器)

实现这一目标的最佳方法是什么?

1 个答案:

答案 0 :(得分:3)

使用Extending Views

<?php
// in your view file
$this->assign('title', 'best title');

$this->start('meta');
echo $this->Html->meta('keywords', 'enter any meta keyword here');
$this->end();
?>

// in your layout file (default.ctp)
<!DOCTYPE html>
<html lang="en">
    <head>
    <title><?php echo $this->fetch('title'); ?></title>
    <?php echo $this->fetch('meta'); ?>
    </head>
    // rest of the layout follows