2017-12-27 961 views
-1

我是codeignitor的新手,試圖製作一個控制器和一個視圖。控制器已成功製作並正在調用視圖。該視圖也被稱爲成功,但圖像不顯示。我試圖把圖片放在與其他文件夾相同的文件夾中,但沒有任何工作。pics not in codeignitor

查看

<!doctype html> 
<html> 
<head> 
    <!-- Latest compiled and minified CSS --> 
    <meta charset="utf-8"> 
    <title>Untitled Document</title> 
    <!--<link href="/assists/css/font-awsome.css" rel="stylesheet" type="text/css">--> 
    <!--<link type="text/css" rel="stylesheet" href="/assists/css/stylecinemax.css">--> 
    <link rel="stylesheet" type="text/css" href="style.css"> 
    <link rel="stylesheet" type="text/css" href="style2.css"> 
    <!-- Start CSS Slideshow HEAD section --> 
    <link rel="stylesheet" type="text/css" href="engine1/style.css" /> 
    <script type="text/javascript" src="engine1/jquery.js"></script> 
    <!-- End CSS Slider HEAD section --> 
    <!-- Latest compiled and minified CSS --> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 

    <!-- jQuery library --> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 

    <!-- Latest compiled JavaScript --> 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
</head> 
    <body> 

      <div class="header"> 
       <a class="cinestar" href="#"></a> 
       <a id="membersarealink" style="margin-left: 5%" href="#" class="toplink">Home</a> 
       <a id="corporatelink" href="#" class="toplink">Corporate</a> 
       <div class="imaxbox"> 
         <div class="sponsor"><img src="pics/sponsorlogo.png" height="32"></div> 
        </div> 
        <a id="gallerycinestar" href="#" class="toplink">Gallery</a> 
        <a id="aboutus" href="#" class="toplink">About</a> 
        <a id="contactuscinestar" href="#" class="toplink">Contact</a> 
        <div class="contactinfo"> 
         <h1>(042) 111 cinema</h1> 
         <a href="#" class="socialicon"><img src="googleplus-header.png" width="24"></a> 
         <a href="#" class="socialicon" target="_blank"><img src="../pics/2.png" width="24"></a> 
         <a href="#" class="socialicon" target="_blank"><img src="../pics/imax-logo.png" width="24"></a> 
        </div> 
        <div class="topticker" style="background-color:gainsboro"> 
         <span> 
          <a class="online-booking-dialogue" href="login.php">Login</a> 
          <a class="members-area-dialogue" href="registration.php" target="_blank">MEMBER REGISTRATION</a> 
         </span> 
         <p style="padding-left: 2%"> 
          To get SMS Alerts of our daily schedule and promotions, please dial 111 CINEMA from your cellphone 
         </p> 
        </div> <!--toptickter-->   
      </div> <!--header--> 
     </body> 
     </html> 

控制器

<?php 
class front_page extends CI_Controller{ 
    public function one() 
    { 
     $this->load->view('header'); 
    } 
} 

這是輸出:

output

+0

你有沒有設置在config.php你需要的基本URL。 – user4419336

回答

3

我能夠理解它可以被混淆用於第一定時器但視圖 - 相關文件如圖像,css,.etc。應該放在基本目錄中,例如與您的主要Codeigntier index.php文件相同的目錄。

enter image description here

我喜歡把我的資源名爲assets文件夾中,有一個子文件夾imagescssjsplugins .etc。

然後訪問他們,你就必須這樣做:

<img src="/assets/images/emojis/smiley.gif" alt="Smiley face" height="42" width="42"> 

OR

在你的控制器(或自動加載文件)加載$this->load->helper('url');

<img src="<?php echo base_url('/assets/images/emojis/smiley.gif'); ?>" alt="Smiley face" height="42" width="42"> 
+0

您可以進一步使用['img()'helper](https://www.codeigniter.com/user_guide/helpers/html_helper.html?highlight=helper#img)。 –

+1

你說得對。雖然我個人發現它有點冗長,如果你想添加屬性 - 在這一點上,你可能只是寫出來。 – Alex

1

創建圖像文件夾位於應用程序文件夾的同一級別。

使用base_url(),您可以獲取網站基地的位置。 例如:

<img src="<?php echo base_url(); ?>images/image.png" alt="image" > 

或者,

<img src="<?php echo base_url("/images/image.png"); ?>" alt="image" >