我有一个包含很多视图的网站。在此网站布局中未使用,因此我必须将收藏图标链接放置到所有视图。
<link rel="icon" href="<?php echo base_url(); ?>images/favicon.gif" type="image/gif">
有没有办法使用控制器操作将此链接包含到所有视图,这样我就不需要将此链接放置到所有视图?
我有一个包含很多视图的网站。在此网站布局中未使用,因此我必须将收藏图标链接放置到所有视图。
<link rel="icon" href="<?php echo base_url(); ?>images/favicon.gif" type="image/gif">
有没有办法使用控制器操作将此链接包含到所有视图,这样我就不需要将此链接放置到所有视图?
create 'header.php' in your 'Views' folder
at there place your icon
header.php
<link rel="icon" href="<?php echo base_url(); ?>images/favicon.gif" type="image/gif">
at your controller add this line
$this->load->view('header);
Example
function page1()
{
$this->load->view('header');
$this->load->view('page1');
}
function page2()
{
$this->load->view('header');
$this->load->view('page2');
}
Use a template library like: https://github.com/philsturgeon/codeigniter-template
From the user guide:
Layouts in this library are very similar to layouts in Ruby on Rails and other frameworks. The basic idea is that most of your pages will share the same header, footer, wrapping navigation, etc ed:[including favicon] and only the actual body of the page will change. Using this logic you can avoid repeating yourself and having lots of similar HTML.