I have ajax call to PHP function as :
$.ajax({
url: 'Link',
type: 'POST',
dataType : 'json',
data: {'txtFromOrderDate' : '2014-08-01','txtToOrderDate' : '2014-08-05'},
success: function() {
window.location = 'Link';
}
});
PHP function as:
public function createZipAction($txtFromOrderDate,$txtToOrderDate)
{
date_default_timezone_set('Australia/Melbourne');
$date = date('m:d:Y H:i:s', time());
$exportBatch = $date;
$order = $this->getTableGateway('order');
$select = new Select();
$select->from('order')
->join('user', 'order.user_id = user.id', array('email'))
->where ("order.created between ".$txtFromOrderDate." and '2014-08-03' ");
//->where ('order.created between '.$txtFromOrderDate.' and '.$txtToOrderDate);
$data = $order->selectWith($select)->toArray();
$batchDir = __DIR__ . '/../../../../../data/export/batch/' . $exportBatch;
if(is_dir($batchDir) == false)
mkdir($batchDir);
$csvFile = fopen($batchDir . '/order.csv', 'w');
$i = 0;
foreach($data as $record) {
if($i==0) fputcsv($csvFile, $this->getCsvHeader($record));
fputcsv($csvFile, $this->updateCsvLine($record));
$pngTmpFile = $this->saveTmpImage($record['plate_id']);
$this->savePlatePdf($pngTmpFile, $exportBatch, $record['id']);
unlink($pngTmpFile);
$i++;
}
fclose($csvFile);
$filter = new \Zend\Filter\Compress(array(
'adapter' => 'Zip',
'options' => array(
'archive' => $batchDir . '.zip'
)
));
$filter->filter($batchDir);
$fileToDownload=$batchDir . '.zip';
$this->downloadOrderCSVAction($fileToDownload);
echo "exported: $i records.";
die();
}
Here when i supply dates to this function, Its not getting dates.
But when i write dates hard-code in php function as:
$txtFromOrderDate='2014-08-01'
$txtToOrderDate='2014-08-05'
Then further function works as expected.
what can be the issue???
Please help me.
$txtFromOrderDate = $_POST['txtFromOrderDate'];etc ... when you POST to PHP, those variables are not set as globals, but are set in the $_POST array.