我正在尝试将参数从Yii MVC
传递到CodeIgniter
模型方法,并在时间间隔之间搜索结果;
created
属性的值为26/2/2014
;
query
是否会使用where
条款执行并连接关于字段created
的两个get_where
子句?
或者它只会执行get_where
子句?
我看不到结果,但正在传递created
值;
created
字段在timestamp
中存储为db
值,我使用date picker
选择day/month/year
,然后传递值通过api
,然后我创建24 hour
时间间隔
这就是我被卡住的地方;
ps:使用EActiveResource
代替ActiveRecord
并通过使用api
codeIgniter
传递数据时,这是一个很好的示例
public function findAll($params) {
if (!empty($params)) {
if (isset($params['created'])) {
$e = explode('/', $params['created']);
$month = $e[1];
$day = $e[0];
$year = $e[2];
$start = mktime(0, 0, 0, $month, $day, $year);
$end = mktime(23, 59, 59, $month, $day, $year);
$this->db->where('created >', $start);
$this->db->where('created <', $end);
}
$query = $this->db->get_where($this->_table, $params);
} else {
$query = $this->db->get($this->_table);
}
$ret = $query->result_array();
foreach ($ret as $key => $value) {
$ret[$key]['order_id'] = $value['id'];
}
return (isset($ret) && !empty($ret)) ? $ret : false;
}
我尝试在$params['created']
中设置yii
的值并将其传递给codeIgniter
,以确保我通过if
;
在codeIgniter
模型中我有:
if (!empty($params)) {
if (isset($params['created'])) {
$this->db->where('created >=', 1393246473);
$this->db->where('created <=', 1393404935);
}
$query = $this->db->get_where($this->_table, $params);
} else {
$query = $this->db->get($this->_table);
}
$ret = $query->result_array();
结果仍然没有数据;
任何想法?
答案 0 :(得分:0)
试试这个
public function findAll($params) {
if (!empty($params)) {
if (isset($params['created'])) {
$e = explode('/', $params['created']);
$month = $e[1];
$day = $e[0];
$year = $e[2];
$start = mktime(0, 0, 0, $month, $day, $year);
$end = mktime(23, 59, 59, $month, $day, $year);
$this->db->where(array('created >'=> $start, 'created <'=> $end));
}
$query = $this->db->get($this->_table);
} else {
$query = $this->db->get($this->_table);
}
$ret = $query->result_array();
foreach ($ret as $key => $value) {
$ret[$key]['order_id'] = $value['id'];
}
return (isset($ret) && !empty($ret)) ? $ret : false;
}
如果你想使用get_where然后传递数组中的所有条件
$this->db->get_where('mytable', array('id' => $id, 'created' => $cre), $limit, $offset);
你也可以编写一个sql查询,如: -
$sql = "SELECT * FROM example WHERE payment_status = '0' AND intial_pay_status = '1'";
$query = $this->db->query($sql);
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
//echo '<pre>'; print_r($row);
}
}