如何将信息从一个模型调用到另一个Codeigniter
我有一段时间一直在关注这个问题。我想不出来。我在reed Documanation上做了很多视频,尝试了10种不同的方法,但都没有效果。所以我有一个视图/模型,在本例中,目的地和我有单独的报价文件。两者的控制器都在一个文件中。我希望目的地中的信息也能转到报价。请帮助我,我无法找出我缺少的内容: 以下是最重要的部分: destination_model.php如何将信息从一个模型调用到另一个Codeigniter,codeigniter,model-view-controller,codeigniter-3,Codeigniter,Model View Controller,Codeigniter 3,我有一段时间一直在关注这个问题。我想不出来。我在reed Documanation上做了很多视频,尝试了10种不同的方法,但都没有效果。所以我有一个视图/模型,在本例中,目的地和我有单独的报价文件。两者的控制器都在一个文件中。我希望目的地中的信息也能转到报价。请帮助我,我无法找出我缺少的内容: 以下是最重要的部分: destination_model.php <?php class Destination_model extends CI_Model { public f
<?php class Destination_model extends CI_Model
{
public function getDestinationDetails($slug) {
$this->db->select('
id,
title,
information
');
$this->db->where('slug', $slug);
$query = $this->db->get('destinations')->row();
if(count($query) > 0)
{
return $query;
}
else
{
// redirect(base_url());
}
}
public function getOffersByDestination($destination_id)
{
$this->db->select('
o.short_title,
o.price,
o.currency,
o.information,
o.long_title_slug,
oi.image,
c.slug as parent_category
');
$this->db->from('offers o');
$this->db->join('offers_images oi', 'oi.offer_id = o.id', 'left');
$this->db->join('categories c', 'c.id = o.category');
$this->db->group_by('o.id');
$this->db->where('o.destination', $destination_id);
$this->db->where('o.active', '1');
return $this->db->get();
} }
我只需要标题和目的地的信息。
以下是报价的整个控制器:
$data = $this->slugs_model->getOfferDetails(strtok($this->uri->segment(2), "."));
$this->load->model('frontend/offers_model');
$this->load->model('frontend/destination_model');
$this->params['main'] = 'frontend/pages/offer_details';
$this->params['title'] = $data->long_title;
$this->params['breadcumb'] = $this->slugs_model->getSlugName($this->uri->segment(1));
$this->params['data'] = $data;
$this->params['images'] = $this->slugs_model->getOfferImages($data->id);
$this->params['similar'] = $this->slugs_model->getSimilarOffers($data->category, $data->id);
$this->params['destination'] = $this->destination_model->getOffersByDestination($data->id);
$this->params['offers'] = $this->offers_model->getImportantOffers($data->offers, $data->category, $data->id);
从模型中获取查询结果后,需要生成查询结果, e、 g:row_array(),此函数返回单个结果行。 这是文件: 试试这个:
$this->load->model('frontend/destination_model');
$data['destination'] = $this->destination_model->getOffersByDestination($data->id)->row_array();
$this->load->view('view_name', $data);
在您的视图中,echo$destination['attribute_name']代码>,,
或者你可以打印数组,看看它是否工作print\r($destination)代码>如何在“报价详情”中回显查看目的地信息,例如?
$this->load->model('frontend/destination_model');
$data['destination'] = $this->destination_model->getOffersByDestination($data->id)->row_array();
$this->load->view('view_name', $data);