php - 在 CodeIgniter (MVC) 中从内容文件设置页面标题

标签 php codeigniter templates

我的 CodeIgniter 网站的 Controller 设置如下:

$this->load->view('head', $data); // Contains <head> stuff
$this->load->view('header', $data); // Nav and sidebars
$this->load->view($this->uri->segment(1), $data); // Main page content
$this->load->view('footer', $data); // Footer

我的问题是关于在哪里存储 <title>标签的内容。理想情况下,它会包含页面内容(第三个加载的 View ),但是如何将其放入 <title> 中?第一个 View 中已加载哪个标签?

我读到过,让 JavaScript 设置标题是不好的,因为它与搜索引擎机器人不兼容。

我还读过一个建议,说有一个包含所有页面的大 View 文件

最佳答案

对于更改页面标题,这是更好的方法。 在您的配置文件中添加此参数:

$config['pageTitle'] = 'Book Store';

在模板页面中:

<title><?=$this->config->config["pageTitle"]?></title>

在您喜欢的任何页面中更改此配置:

$this->config->config["pageTitle"] = $detail[0]['Title'];

每次您都可以轻松更改标题。

关于php - 在 CodeIgniter (MVC) 中从内容文件设置页面标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11376745/

相关文章:

PHP 表单代码损坏

php - 结构\H、\V 和\N 是什么意思?

php - 将动态内容添加到 codeigniter 中的模板

php - 在选择框中动态显示值在 codeigniter 中不起作用

php - Doctrine Fatal Error - 未知关系别名

jquery - 在页面模板中使用自定义 jquery

C++ typedef 和子类化

php - Magento PHP在表中创建了一个新列,尝试使用列来过滤和执行条件语句

PHP标点符号混淆

c++ - 如何在 C++ 中为嵌套模板数字类型类编写构造函数?