将值从我的视图传递到我的模型

时间:2018-01-05 08:10:35

标签: mysql codeigniter

我想将视图中的值传递给我的模型。我想将$ plate值传递给我的模型,以获得与$ plate匹配的所有数据。这是我的代码:

查看

<a href="<?=base_url()?>services/view_services?plate=<?php echo  $plate; ?>">
<button type="button" class="btn btn-primary">View Services</button>

控制器

public function view_services()
{
    $data['results'] = $this->Services_model->fetch_car_services($config['per_page'], $page);
    $this->load->view('car_services', $data);
}

模型

public function fetch_car_services($plate)
{
    $this->db->where('car_plate_number =', $plate);
    $this->db->order_by('created_datetime', 'DESC');
    $query = $this->db->get('service_jobs');
    $result = $query->result();
    $this->db->save_queries = false;

    return $result;
}  

它似乎不起作用。提前谢谢。

2 个答案:

答案 0 :(得分:1)

你必须使用你的方法以某种方式得到变量:

 libvlc_media_stats_t preStat;
    VlcMethods.Instance.Libvlc_media_get_stats(mediaObj, out preStat);

    while (true)
    {
        yield return new WaitForSeconds(1f);

        libvlc_media_stats_t t;
        VlcMethods.Instance.Libvlc_media_get_stats(mediaObj, out t);

        int playedBuff = t.i_demux_read_bytes - preStat.i_demux_read_bytes;            
        int downBuff = t.i_read_bytes - preStat.i_read_bytes;
        int storageBuff = t.i_read_bytes - t.i_demux_read_bytes;

        sumStorageBuffer -= storagebuffQueue.Dequeue();
        storagebuffQueue.Enqueue(storageBuff);
        sumStorageBuffer += storageBuff;

        sumDownBuff -= downBuffQueue.Dequeue();
        downBuffQueue.Enqueue(downBuff);
        sumDownBuff += downBuff;

        averageStorageBuffer = (sumStorageBuffer / (float)storagebuffQueue.Count) / playedBuff;
        averageDownloadBuffer = (sumDownBuff / (float)downBuffQueue.Count) / playedBuff;

        preStat = t;

更好的做事方式:

//services/view_services?plate=someplate
public function view_services() {
    $plate = $this->input->get('plate');
    if (is_null($plate)) {
        // error!
    }
    $data['results'] = $this->Services_model->fetch_car_services($plate);
    $this->load->view('car_services', $data);
}

请检查错误!我已经为你做了一半的工作,你只需要弄清楚你想如何处理它们。这还包括检查模型中的//services/view_services/someplate public function view_services($plate = null) { if (is_null($plate)) { // error! } $data['results'] = $this->Services_model->fetch_car_services($plate); $this->load->view('car_services', $data); } 或控制器中的num_rows > 0,如果是这种情况则发送错误。如果你不这样做,你在视图中的foreach就会失败。

答案 1 :(得分:0)

查看:

 <a href="<?php echo site_url('services/view_services/').$plate; ?>"></a>

控制器:

 public function view_services($plate)
     {
         $data['results'] = $this->Services_model->fetch_car_services($config['per_page'], $page);

         $this->load->view('car_services', $data);
     }