我在项目中使用YII 1.1。我有一个SQL查询来根据cjuidatepicker中选择的日期创建一个图表。
以下是我在视图上的代码
<div class="row">
<?php
echo $form->labelEx($model, 'datefrom');
?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name' => 'datefrom',
'model' => $model,
'attribute' => 'datefrom',
'id' => 'datefrom',
// additional javascript options for the date picker plugin
'options' => array(
'showAnim' => "slideDown",
'changeMonth' => true,
'numberOfMonths' => 1,
//'showOn' => "button",
//'buttonImageOnly' => false,
'dateFormat' => "yy-mm-dd",
'showButtonPanel' => true,
'onClose' => 'js:function(selectedDate) { $("#date_from").datepicker("option", "maxDate", selectedDate); }'
)
));
?>
<?php
echo $form->error($model, 'datetime');
?>
</div>
<div class="row">
<?php
echo $form->labelEx($model, 'dateto');
?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name' => 'dateto',
'model' => $model,
'attribute' => 'dateto',
'id' => 'dateto',
// additional javascript options for the date picker plugin
'options' => array(
'showAnim' => "slideDown",
'changeMonth' => true,
'numberOfMonths' => 1,
'dateFormat' => "yy-mm-dd",
'showButtonPanel' => true,
'onClose' => 'js:function(selectedDate) { $("#date_to").datepicker("option", "minDate", selectedDate); }'
)
));
?>
</div>
<div class="row buttons">
<?php
echo CHtml::link('Search', array(
'commLog/statistic',
'datefrom' => 'datefrom',
'dateto' => 'dateto'
));
?>
</div>
这是生成图表的代码。
<?php
$xAxis = Yii::app()->db->createCommand("SELECT comm_mode.commType As Type FROM comm_log inner join comm_mode
ON comm_mode.id=comm_log.modeId where datetime between '2016-06-01' AND '2016-06-08' group by commType")
->select('Type')
->queryColumn();
$data = Yii::app()->db->createCommand("SELECT count(modeId)as Count FROM comm_log inner join comm_mode
ON comm_mode.id=comm_log.modeId where datetime between '2016-06-01' AND '2016-06-08' group by commType")
->select('Count')
->queryColumn();
$data=array_map('intVal', $data);
$this->Widget('ext.highcharts.HighchartsWidget', array(
'options' => array(
'title' => array('text' => 'Total communication type chosen'),
'xAxis' => array(
'categories' => $xAxis,
),
'yAxis' => array(
'title' => array('text' => 'Communication chosen')
),
'series' => array(
array('type' => 'column','name' => 'Quantity','data' => $data,'shadow' => false,
)
)
)
));
?>
我可以生成图表,但我的问题是我必须将用户选择的值传递给我的SQL查询。现在我手动在BETWEEN子句上写日期。 有人可以帮我如何将值传递给我的查询吗? 我被困了很长时间。我是YII的初学者。我需要帮助。