我正在尝试在Ajax请求上打印mysql查询,但未显示。
我的查看页面
点击“搜索”按钮将调用一个Ajax函数
Ajax.js
$(document).ready(function(){
function random_number()
{
return Math.floor(Math.random() * 255);
}
$("#btningSrch").click(function(){
$("#rpts").html("<img src='https://xx.xx.xx.xx/project/img/ajaxLoader1.gif' />");
alert("hi");
$.ajax({
type: "GET",
url: "https://xx.xx.xx.xx/project/controller/view/"+random_number(),
data: "startDate="+$("#startDate").val()+"&type="+$("#type").val()+"&orderby="+$("#orderby").val(),
dataType: "html",
success: function(msg){
alert(msg);
$("#rpts").html(msg);
}
});
return false;
});
});
Controller.php
function show_in_summary()
{
$this->isLoggedIn();
//pr($this->request); exit;
//echo $this->request->is('ajax');
if ($this->request->is('ajax'))
{
//echo 2222; exit; //$this->layout = 'index3';
//pr($this->InTrafficSummary->txtChk($this->params['url']['startDate']));
//die();
//pr($this->request->query);exit;
//if ($this->InTrafficSummary->txtChk($this->request->query['startDate']))
//{
$this->set('record',1);
$this->loadModel('InOutTrafficSummary');
$data = $this->InOutTrafficSummary->readInBoundTrafficSummary($this->request->query['startDate'],
$this->request->query['type'],$this->request->query['orderby']);
$this->set('reports',$data[0]);
$this->set('total',$data[1]);
$this->set('date',date("Y-m-d",strtotime($this->request->query['startDate'])));
$this->set('type',$this->request->query['type']);
//}
//else
//{
//$this->set('reports',array());
//$this->set('record',0);
//$this->set('total',array());
//$this->set('date',date("Y-m-d",strtotime($this->params['url']['startDate'])));
//$this->set('type',$this->params['url']['type']);
//}
}
}
Model.php
$rs = $this->find('all', array('joins' => array(array(
'table' => 'InOutTrafficSummary',
'alias' => 'Carriers',
'type' => 'INNER',
'conditions' => array(
'Carriers.CarrierId = '.$useTable.'.FK_IngressCarrierId'))),
'conditions' => array('InDate' => date("Y-m-d",strtotime("-1 days"))),
'fields' => array(
'FK_IngressCarrierId,CarrierName,Sum(TotalCalls),Sum(ConnectedCalls),sum(Duration),(Sum(ConnectedCalls)/Sum(TotalCalls))*100,sum(Duration)/Sum(ConnectedCalls),sum(SaleAmount)'),'group' => 'FK_IngressCarrierId','order' => 'sum(Duration) DESC'));
echo $this->element('sql_dump'); exit;
我想在上面打印查询,因为它没有显示任何记录,我假设格式有误,因此需要查看整个查询。所有其他东西都工作正常。
我是CakePHP的新手。
答案 0 :(得分:0)
尝试一下
debug($this->YOUR_MODEL_NAME->getDataSource()->getLog(false, false));
答案 1 :(得分:0)
我在AppModel.php中添加了以下辅助函数
/**
* Get the last queries
* Wrapper function
*/
public function getLastQueries() {
return $this->getDataSource()->getLog(false, false);
}
您可以轻松地在show_in_summary()函数中调用它:
debug($this->InOutTrafficSummary->getLastQueries());