我正在尝试使用cake3制作搜索表单,以获取2个日期之间的值。但我收到错误,不知道为什么。
这是我的表格:
<?php echo $this->Form->create('CustodyKeys', array('type' => 'get',
'url' => array(
'controller' => 'CustodyKeys','action' => 'resultypeLongTerm'
)));?>
<div class="row">
<div class="form-group col-md-12">
<?php
echo $this->Form->input('keys_custody_status_name', ['placeholder'=>__('Enter Custody statue'),'class' => 'form-control','label'=>__('Custody statue')]);
?>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<?php
echo $this->Form->input('received_date_from', ['type' => 'text', 'placeholder' => __('Received Date From'), 'label' => __('Received Date From'), 'class' => 'form-control hasGorgianDatePicker','value'=>'from']);
?>
</div>
<div class="form-group col-md-6">
<?php
echo $this->Form->input('received_date_to', ['type' => 'text', 'placeholder' => __('Received Date to'), 'label' => __('Received Date to'), 'class' => 'form-control hasGorgianDatePicker']);
?>
</div>
这是我在控制器上的功能:
$date_start = 'received_date_from';
$date_end = 'received_date_to';
$conditions = $this->CustodyKeys->find(
'all',array('conditions'=>array('CustodyKeys.received_date_from >=' => array($date_start),
'CustodyKeys.received_date_to <=' => array($date_end)))
) ;
$this->set('data', $conditions);
这是显示搜索结果的ctp:
<?php foreach ($data as $custodyKey): ?>
<tr>
<td><?= $custodyKey->id ?></td>
调试给我的结果:
'(help)'=&gt; '这是一个Query对象,用于获取结果执行或迭代它。', 'sql'=&gt; 'SELECT CustodyKeys.id AS
CustodyKeys__id
,CustodyKeys.holders_keys_id ASCustodyKeys__holders_keys_id
,CustodyKeys.keys_management_id ASCustodyKeys__keys_management_id
,CustodyKeys.keys_custody_type_id ASCustodyKeys__keys_custody_type_id
,CustodyKeys.keys_custody_status_id AS {{1} },CustodyKeys.received_date ASCustodyKeys__keys_custody_status_id
,CustodyKeys.return_date ASCustodyKeys__received_date
,CustodyKeys.last_status_date ASCustodyKeys__return_date
,CustodyKeys.notes ASCustodyKeys__last_status_date
FROM custody_keys CustodyKeys WHERE(CustodyKeys.received_date_from&gt ; =:c0 AND CustodyKeys.received_date_to&lt; =:c1)', 'params'=&gt; [ ':c0'=&gt; [ 'value'=&gt; [ (int)0 =&gt; 'received_date_from' ] 'type'=&gt;空值, 'placeholder'=&gt; 'C0' ] ':c1'=&gt; [ 'value'=&gt; [ (int)0 =&gt; 'received_date_to' ] 'type'=&gt;空值, 'placeholder'=&gt; 'C1' ] ],
答案 0 :(得分:0)
要将查询对象转换为数组,您可以使用:
$data->toArray()
答案 1 :(得分:0)
试试这个
$conditions = $this->CustodyKeys->find('all',
array('conditions'=>
array('CustodyKeys.received_date_from >= '. $date_start,
'CustodyKeys.received_date_to <= '. $date_end))
);