[英]How to solve the date range search using CodeIgniter
Controller code 控制器代码
public function getcari(){
$tglawal=date('Y-m-d', strtotime($this->input->post('tgl1', TRUE)));
$tglakhir=date('Y-m-d', strtotime($this->input->post('tgl2', TRUE)));
$data['detail']=$this->traffic_model->cari($tglawal,$tglakhir);
$this->load->view('daftar_traffic', $data); //menampilkan data yang sudah dicari
}
Model Code 型号代码
function cari($tglawal,$tglakhir){
$this->db->select('DATE_FORMAT(tgl, %d %M %Y) AS tanggal,COUNT(IF(kategori.parent=35 , VALUE, NULL)) AS Software, COUNT(IF(kategori.parent=33 , VALUE, NULL)) AS Indent, COUNT(IF(kategori.parent=32 , VALUE, NULL)) AS Ready, COUNT((DATE_FORMAT(tgl, %d - %m - %Y))) AS Total'); //changed the code here from COUNT(clients.id) AS num_rows
$this->db->from('masalah ');
$this->db->where('DATE(masalah.tgl) >=', $tglawal);
$this->db->where('DATE(masalah.tgl) <=', $tglakhir);
$this->db->join('kategori, kategori.kategori=masalah.kategori', 'left');
$this->db->group_by('tanggal');
$query = $this->db->get();
return $query->result();
}
View Code 查看代码
<form action="<?php echo site_url('traffic/getcari');?>" method="post"><input type="date" name="tgl1" palceholder="Input date" requaried="true" /> <input type="date" name="tgl2" palceholder="Input date" requaried="true" /><button type="submit">Cari</button> <a href="<?php echo site_url('traffic'); ?>" style="text-decoration:none; color: black;">Reset</a>
the errors... Warning: include(C:\\xampp\\htdocs\\portalacw\\application\\views\\errors\\html\\error_php.php): failed to open stream: No such file or directory in C:\\xampp\\htdocs\\portalacw\\system\\core\\Exceptions.php on line 269
错误...警告:include(C:\\ xampp \\ htdocs \\ portalacw \\ application \\ views \\ errors \\ html \\ error_php.php):无法打开流:C:\\ xampp \\ htdocs \\ portalacw中没有此类文件或目录\\ system \\ core \\ Exceptions.php在第269行
Warning: include(): Failed opening 'C:\\xampp\\htdocs\\portalacw\\application\\views\\errors\\html\\error_php.php' for inclusion (include_path='C:\\xampp\\php\\PEAR') in C:\\xampp\\htdocs\\portalacw\\system\\core\\Exceptions.php on line 269
警告:include():无法在C:\\中打开'C:\\ xampp \\ htdocs \\ portalacw \\ application \\ views \\ errors \\ html \\ error_php.php'(include_path ='C:\\ xampp \\ php \\ PEAR')第269行的xampp \\ htdocs \\ portalacw \\ system \\ core \\ Exceptions.php
Fatal error: Call to a member function cari() on null in C:\\xampp\\htdocs\\portalacw\\application\\modules\\traffic\\controllers\\traffic.php on line 24
致命错误:在第24行的C:\\ xampp \\ htdocs \\ portalacw \\ application \\ modules \\ traffic \\ controllers \\ traffic.php中,调用成员函数cari()为null
Warning: include(C:\\xampp\\htdocs\\portalacw\\application\\views\\errors\\html\\error_php.php): failed to open stream: No such file or directory in C:\\xampp\\htdocs\\portalacw\\system\\core\\Exceptions.php on line 269
警告:include(C:\\ xampp \\ htdocs \\ portalacw \\ application \\ views \\ errors \\ html \\ error_php.php):无法打开流:C:\\ xampp \\ htdocs \\ portalacw \\ system \\ core \\中没有此类文件或目录第269行的Exceptions.php
Warning: include(): Failed opening 'C:\\xampp\\htdocs\\portalacw\\application\\views\\errors\\html\\error_php.php' for inclusion (include_path='C:\\xampp\\php\\PEAR') in C:\\xampp\\htdocs\\portalacw\\system\\core\\Exceptions.php on line 269
警告:include():无法在C:\\中打开'C:\\ xampp \\ htdocs \\ portalacw \\ application \\ views \\ errors \\ html \\ error_php.php'(include_path ='C:\\ xampp \\ php \\ PEAR')第269行的xampp \\ htdocs \\ portalacw \\ system \\ core \\ Exceptions.php
Warning: include(C:\\xampp\\htdocs\\portalacw\\application\\views\\errors\\html\\error_php.php): failed to open stream: No such file or directory in C:\\xampp\\htdocs\\portalacw\\system\\core\\Exceptions.php on line 269
警告:include(C:\\ xampp \\ htdocs \\ portalacw \\ application \\ views \\ errors \\ html \\ error_php.php):无法打开流:C:\\ xampp \\ htdocs \\ portalacw \\ system \\ core \\中没有此类文件或目录第269行的Exceptions.php
Warning: include(): Failed opening 'C:\\xampp\\htdocs\\portalacw\\application\\views\\errors\\html\\error_php.php' for inclusion (include_path='C:\\xampp\\php\\PEAR') in C:\\xampp\\htdocs\\portalacw\\system\\core\\Exceptions.php on line 269 '
警告:include():无法在C:\\中打开'C:\\ xampp \\ htdocs \\ portalacw \\ application \\ views \\ errors \\ html \\ error_php.php'(include_path ='C:\\ xampp \\ php \\ PEAR')第269行的xampp \\ htdocs \\ portalacw \\ system \\ core \\ Exceptions.php'
pleas help me 请帮我
In my opinion, your problem is because you didn't load the model correctly. 我认为您的问题是因为未正确加载模型。 So your controller took the
traffic_model
to be null
. 因此,您的控制器将
traffic_model
设置为null
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.