Codeigniter |将metas添加为标头的变量

时间:2017-10-05 21:23:46

标签: php codeigniter

问题。如何添加或将标签添加为标头的变量的最佳做法是什么。当我需要将一些类似的元数据发送到几个控制器并希望将其添加为头模板的变量时。 然后我就可以回复$ METAS [' title'],$ METAS [' description'],就像那样。

我做到了,但试图通过' pre_controller'添加和' pre_system'钩而不工作。

class seo_metas
{
    public function __constructor() {

        $SEOMetas['descripcion'] = "";
        $SEOMetas['keywords'] = "";
        $SEOMetas['title'] = "";
        $SEOMetas['subtitle'] = "";
        $SEOMetas['author'] = "";
        $SEOMetas['charset'] = "utf-8";
    }

    public function get_seo_metas() {

        $SEOMetas['descripcion'] = "";
        $SEOMetas['keywords'] = "Dev";
        $SEOMetas['title'] = "SM";
        $SEOMetas['subtitle'] = "Dev";
        $SEOMetas['author'] = "Sam";
        $SEOMetas['charset'] = "utf-8";
    }

    public function set_seo_metas($descripcion, $keywords, $title, $subtitle, $author, $charset) {

        $SEOMetas['descripcion'] = $descripcion;
        $SEOMetas['keywords'] = $keywords;
        $SEOMetas['title'] = $title;
        $SEOMetas['subtitle'] = $subtitle;
        $SEOMetas['author'] = $author;
        $SEOMetas['charset'] = $charset;
    }

}

挂钩

$hook['pre_controller'][] = array(
    'function' => 'get_seo_metas',
    'filename' => 'seo_metas',
    'filepath' => 'hooks'
    );

标题

<meta charset=<?php echo $SEOMetas['charset']?> />
    <title><?php ($SEOMetas['title'] . $SEOMetas['subtitle'] )?> </title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="author" content=<?php echo $SEOMetas['author']?> />
    <meta name="description" content=<?php echo $SEOMetas['author']?> />
    <meta name="keywords" content=<?php echo $SEOMetas['keyworkds']?> />

非常感谢!

0 个答案:

没有答案