我有博客,这是有关的现金在代码点火器的Franework。 我有一个报价数据库。 我想从数据库获取所有的报价到index.php
(视图)。 这是我的默认设置。 问题是如何在index.php
中获取数据。 index.php
是我网站的主页。
我所尝试的
user.php(控制器)
public function testing()
{
$this->load->view('user/index.php');
$this->load->model('showoffers');
$offers = $this->showoffers->showoffersmodel();
$this->load->view('showoffers',['offers'=>$offers]);
}
showoffers.php(模型)
<?php
class showoffers extends CI_Model
{
public function showoffersmodel()
{
$q = $this->db->select('*')
->from('offers')
->get();
return $q->result();
}
}
?>
index.php(视图)
<?php if(count($offers)): ?>
<?php foreach ($offers as $emp): ?>
<div class="text-center">
<br>
<img style="margin-left: -80%;" border="0" height="100" width="120" src="<?php echo base_url('image/amazon.png'); ?>" class="rounded" alt="...">
<h2><?= $emp->title; ?></h2>
<div class="row">
<div class="col-sm-6">
</div>
<div class="col-sm-6 details">
<?= $emp->details; ?>
<br>
<br>
<a style="font-size: 15px;" href="<?= $emp->link; ?>" class="badge badge-warning">Click Here to collect Cashback</a>
</div>
</div>
<button type="button" class="btn btn-success btn78">
<i class="fa fa-check" aria-hidden="true"></i>
Verified
</button>
</div>
<?php endforeach; ?>
<?php else: ?>
<?php endif; ?>
我得到的错误
Unable to load the requested file: showoffers.php
请帮帮我!!!
控制器:
public function testing()
{
$data['offers'] = $this->showoffers->showoffersmodel();
$this->load->view('user/index', $data);
}
型号:
public function showoffersmodel()
{
$query = $this->db->get('offers');
return $query->result();
}
查看:
<?php if(count($offers)): ?>
<?php foreach ($offers as $emp): ?>
<div class="text-center">
<br>
<img style="margin-left: -80%;" border="0" height="100" width="120" src="<?php echo base_url('image/amazon.png'); ?>" class="rounded" alt="...">
<h2><?= $emp->title; ?></h2>
<div class="row">
<div class="col-sm-6">
</div>
<div class="col-sm-6 details">
<?= $emp->details; ?>
<br>
<br>
<a style="font-size: 15px;" href="<?= $emp->link; ?>" class="badge badge-warning">Click Here to collect Cashback</a>
</div>
</div>
<button type="button" class="btn btn-success btn78">
<i class="fa fa-check" aria-hidden="true"></i>
Verified
</button>
</div>
<?php endforeach; ?>
<?php endif; ?>
希望这有用!