如何将具有相同文件夹的图标显示到另一个页面(链接)

时间:2019-08-07 08:57:27

标签: javascript php html codeigniter bootstrap-4

我想询问有关显示图标(图片)的问题。图标仅在路径“ img / icons”中。但是,当我想在链接为“ xxx / xxx / xxx / xxx”的另一个页面中显示时,没有显示该图标。仅显示带有链接“ xxx / xxx”的图标。因为图标显示在navbar.php中。但是navbar.php包含在所有链接中。

如何显示带有我的代码的图标?或者您还有另一个代码?

请帮助我

我正在使用带有Bootstrap的Codeigniter框架。

这是我的代码

<?php 
$current_url = current_url();
?>
<div class="collapse navbar-collapse" id="nav-content">   
    <ul class="navbar-nav">
        <li class="nav-item">
            <a  class="nav-link <?=(site_url('/')==$current_url)?'clicks':''?>" href="<?php echo site_url('/') ?>"><img class="iconics" src=".\assets\img\icon\home-icon.png" /></a>
        </li>
        <li class="nav-item">
            <a class="nav-link <?=(site_url('product')==$current_url)?'clicks':''?>" href="<?php echo site_url('product') ?>"><img class="icons" src=".\assets\img\icon\product-icon.png" /></a>
        </li>
        <li class="nav-item">
            <a class="nav-link onclicks <?=(site_url('feed')==$current_url)?'clicks':''?>" href="<?php echo site_url('feed') ?>"><img class="icons" src=".\assets\img\icon\feed-icon.png" /></a>
        </li>
        <li class="nav-item">
            <a class="nav-link <?=(site_url('confirm')==$current_url)?'clicks':''?>" href="<?php echo site_url('confirm') ?>"><img class="icons" src=".\assets\img\icon\payment-icon.png" /></a>
        </li>
        <li class="nav-item">
            <a class="nav-link <?=(site_url('contact')==$current_url)?'clicks':''?>" href="<?php echo site_url('contact') ?>"><img class="icons" src=".\assets\img\icon\contact-icon.png" /></a>
        </li>
    </ul>
</div>

2 个答案:

答案 0 :(得分:1)

如红色所示,请使用绝对路径,例如:

<div class="collapse navbar-collapse" id="nav-content">   
    <ul class="navbar-nav">
        <li class="nav-item">
            <a  class="nav-link <?=(site_url('/')==$current_url)?'clicks':''?>" href="<?php echo site_url('/') ?>"><img class="iconics" src="<?php echo site_url('/') ?>assets\img\icon\home-icon.png" /></a>
        </li>
        <li class="nav-item">
            <a class="nav-link <?=(site_url('product')==$current_url)?'clicks':''?>" href="<?php echo site_url('product') ?>"><img class="icons" src="<?php echo site_url('/') ?>assets\img\icon\product-icon.png" /></a>
        </li>
        <li class="nav-item">
            <a class="nav-link onclicks <?=(site_url('feed')==$current_url)?'clicks':''?>" href="<?php echo site_url('feed') ?>"><img class="icons" src="<?php echo site_url('/') ?>assets\img\icon\feed-icon.png" /></a>
        </li>
        <li class="nav-item">
            <a class="nav-link <?=(site_url('confirm')==$current_url)?'clicks':''?>" href="<?php echo site_url('confirm') ?>"><img class="icons" src="<?php echo site_url('/') ?>assets\img\icon\payment-icon.png" /></a>
        </li>
        <li class="nav-item">
            <a class="nav-link <?=(site_url('contact')==$current_url)?'clicks':''?>" href="<?php echo site_url('contact') ?>"><img class="icons" src="<?php echo site_url('/') ?>assets\img\icon\contact-icon.png" /></a>
        </li>
    </ul>
</div>

原因与您的代码有关,它将尝试查找与您当前URL相关的图标,该图标不适用于您首页以外的URL。

答案 1 :(得分:0)

 First set your base url in config.php then in your     controller
  retrieve the the base url.
  function index (){
      $data ['base'] = $this->config->item ('base_url');
      $this->load->view ('your_view',$data);
  }
 So if your bootstrap is located 
  http://example.com/css/icons.css
 In your view
     <link rel="stylesheet" type="text/css" href="<?php echo        
    $base;?>css/icons.css">

 Include that in whatever view do you have. In that case you can acccess your icons in whatever path your view is located