当我使用其他模型函数调用视图时,图像无法加载到页面上

时间:2019-06-12 20:44:27

标签: php mysql

我已经在模型中创建了一种方法,可以使用图像调用数据库中的所有事件-工作正常,然后我想找到与邮政编码匹配的事件,因此创建了另一个函数,当填写并提交搜索栏时会调用该函数。这个功能可以正常工作并从数据库中加载所有信息,除了图像,甚至是索引页面中硬编码的图像,我无法弄清楚自己做错了什么或为什么不起作用。

我已经测试了phpMyAdmin中的代码,并且该函数返回了图像路径,索引页必须没问题,因为它返回了另一个函数的所有内容,而这又离开了控制器,但我也看不到任何错误。

模型功能代码:

function FindEventByPostcode($id){
    $this->db->query("SELECT 

        concert.concert_id as concertId,
        event_type.id as typeId,
        concert.type_id as typeCId,
        concert.concert_name as concertName,
        concert.date as concertDate,
        users.name as userName,
        concert.date as date,
        concert.post_code as post_code,
        concert.info as info,
        images.image_path as imagePath,
        event_type.type as type
        FROM concert
        JOIN event_type
        ON concert.type_id = event_type.id
        JOIN users  ON 
        users.id = concert.user_id                
        JOIN images ON  concert.image_id = images.id
        WHERE  concert.post_code = :post_code
        ORDER BY concert.date DESC"
    );

    $this->db->bind(':post_code', $id);

    $results = $this->db->resultSet();

    return $results;
}

控制器代码:

  $events = $this->eventModel->getEventTypes();
  class Pages extends Controller {
  public function __construct(){

  $this->eventModel = $this->model('Event');
  $this->userModel = $this->model('User');
  $this->pageModel = $this->model('Page');
  }

 public function index(){
   if(isLoggedIn()){
     redirect('profiles');
  }
  if($_SERVER['REQUEST_METHOD'] == 'POST'){

    $postcode = ($_REQUEST['post_code']);
$event = $this->pageModel->FindEventByPostcode($postcode);

    $data =[
    'title' => 'Forthcoming Events',
    'events' => $event

    ];
    $this->view('pages/index', $data);

    }else{
    $data = [
    'title' => 'Forthcoming Events',
    'events' => $events

    ];

    $this->view('pages/index', $data);

   }


 }
  }

索引页:

 <?php require_once APPROOT . '/views/inc/header.php' ?>
 <div>
 <p>Event Finder</p>
 <form name="postcode" method="post" 
 action="<?php echo URLROOT; ?  >/pages/index">
<input type="text" name='post_code'/>
<input type="submit" value="find event">



</form>

</div>

<div class="col-md-6">
  <h1><?php echo $data['title'] ?></h1>

</div>

<img src="img/concertBanner.jpg" style="width:100%"/>


<?php foreach($data['events'] as $post) : ?>
<div class="card card-body mb-3">
<img class="card-img-top"  src="img/<?php echo $post->userName; ?>/
<?php echo $post->imagePath; ?>" 
  style="width:50%; height:50%;" alt="Card image cap">
  <div class="card-body"> 
  <h4 class="card-title"><?php echo $post->concertName; ?></h4>
  <p class="card-text"> Event Info: <?php echo $post->info ?></p>
  <p class="card-text"><?php echo $post->type ?></p>
  <p></p>
  <div class="bg-light p-2 mb-3">
   Organised by <?php echo $post->userName; ?> 
   on <?php echo $post->date; ?>
  </div>
  <p class="card-text"><?php echo $post->concertName; ?> in 
  <?php echo  $post->post_code; ?> </p>
   <a href="<?php echo URLROOT; ?>/pages/show/
   <?php echo $post->concertId;?>" class="btn btn-dark">More</a>


   </div> 
 </div>
      

没有错误消息,只是断开的图像链接而不是图像。

0 个答案:

没有答案