仅使用代码点火器在主页上显示div

时间:2016-03-16 05:27:08

标签: php codeigniter

我正在尝试仅在我的Codeigniter网站的主页上显示横幅,但不知道如何执行此操作。这是我的代码。

<div class="banner">
  <div class="susy__container bannercontainer" style="position: relative;">
      <h1 class="special">
       <span class="sp1">Affordable</span> 
       <span class="sp2">Business Websites</span> <span class="sp3">Done Fast…</span>
      </h1>
      <h2 class="subtitle special">"Just find a website you like and we will customize it to your business needs, easy as 123!"</h2>
     <a href="../start" class="postbtn btn btn-orange">Start Search <i class="fa fa-arrow-circle-right"></i></a>

  </div>
</div>

我已经尝试了这个,但显示了空白页

<?php if( $this->uri->segment(1) == 'home' || $this->uri->segment(1) = '' ): ?>
  <div class="banner">
    <div class="susy__container bannercontainer" style="position: relative;">
        <h1 class="special"><span class="sp1">Affordable</span> <span class="sp2">Business Websites</span> <span class="sp3">Done Fast…</span></h1>
        <h2 class="subtitle special">"Just find a website you like and we will customize it to your business needs, easy as 123!"</h2>
        <a href="../start" class="postbtn btn btn-orange">Start Search <i class="fa fa-arrow-circle-right"></i></a>
    </div>
</div>
<?php endIf; ?>

3 个答案:

答案 0 :(得分:0)

Codeigniter有mvc构造。您的代码是视图部分。 因此,您将在应用程序/视图中插入主页视图的php文件。

答案 1 :(得分:0)

创建一个像banner这样的视图文件并将你的html代码放在它上面并将其加载到控制器上,例如像这样。

class Home extends CI_Controller
{
     function Inventory()
     {
        parent::__construct();
     }

    function index()
    {   
        $this->load->view('common/header');
        $this->load->view('home/banner');
        $this->load->view('home/home_view');
        $this->load->view('common/footer');
    }   
}

将您的代码放在banner.php文件中并将其放在视图文件夹

<div class="banner">
    <div class="susy__container bannercontainer" style="position: relative;">
        <h1 class="special"><span class="sp1">Affordable</span> <span class="sp2">Business Websites</span> <span class="sp3">Done Fast…</span></h1>
        <h2 class="subtitle special">"Just find a website you like and we will customize it to your business needs, easy as 123!"</h2>
        <a href="../start" class="postbtn btn btn-orange">Start Search <i class="fa fa-arrow-circle-right"></i></a>
    </div>
</div>

答案 2 :(得分:0)

您需要在VIEW中创建三个文件(header,homepage,footer)

基本示例:

class Home extends MY_Controller {

    public function index()
    {
        $this->load->view('header');
        $this->load->view('homepage');
        $this->load->view('footer');
    }

}

homepage.php中添加此文件中的横幅以及主页HTML:

<div class="banner">
    <div class="susy__container bannercontainer" style="position: relative;">
        <h1 class="special"><span class="sp1">Affordable</span> <span class="sp2">Business Websites</span> <span class="sp3">Done Fast…</span></h1>
        <h2 class="subtitle special">"Just find a website you like and we will customize it to your business needs, easy as 123!"</h2>
        <a href="../start" class="postbtn btn btn-orange">Start Search <i class="fa fa-arrow-circle-right"></i></a>
    </div>
</div>

您的header.php文件包含导航,徽标,CSS等。

您的footer.php文件包含页脚链接,js,脚本等

相关问题