For an action in my controller that needs no view, I'm disabling the layout and template like this:
$this->autoRender = false;
And it's all good. However, in that same action I'm echoing a 'pass' or 'fail' to signal my view of the result. The problem is a bunch of text is also echoed: (my 'fail' or 'pass' at the very end)
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
</body>
</html>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<head> ....
This is echoed 8 o 9 times.
How can I get rid of that so only my 'pass' or 'fail' are echoed? Can you help?
I've tried
$this->layout = false; and
$this->render(false);
Thank you so much.
Update:** Just noted it also echoes a bunch of javascrip code out of nowhere, (Removed < for pasting here) e.g.: pre class="cake-error" a href="javascript:void(0);" onclick="document.getElementById('cakeErr5035af14add0c-trace').style.display = (document.getElemen..
This is the whole action **
//This action is called via:
//mysite/qcas/loadProdFromFile/dirId:76
// or
//mysite/qcas/loadProdFromFile/dirId:76/filePath:J:\ep12219 - Air Pollution\Load\prodValues.csv
function loadProdFromFile() {
$this->autoRender = false;
// here we get dir info based on first (and perhaps sole) param received: dirId
$dirName = $this->Qca->Dir->find('first', array(
'recursive' => 0,
'fields' => array('Dir.name'),
'conditions' => array('Dir.id' => $this->request->params['named']['dirId']),
)
);
//if used did not provide filePath param, we use a default location based on dir info
if ((is_null($this->request->params['named']['filePath']))) {
$basedir = '/disk/main/jobs/';
$dirs = scandir($basedir);
$found = 0;
foreach ($dirs as $key => $value) {
if (strpos($value, $dirName['Dir']['name']) > -1) {
$found = 1;
break;
}
}
if (!$found) {
echo 'failfile';
exit;
}
$loadDir = '/disk/main/jobs/' . $value . '/Load/';
$thefiles = glob($loadDir . "*.csv");
$prodFile = $thefiles[0];
} else {
// if user provided a path, we build a unix path
// for some reason the extension is not posted, so we append it: only csv can be processed anyways
$prodFile = AppController::BuildDirsFile($this->request->params['named']['filePath']) . ".csv";
}
// we get here with a working file path
$fileHandle = fopen($prodFile, 'r');
if ($fileHandle) {
// start processing file to build $prodata array for saving to db
$counter = 0;
while (!feof($fileHandle)) {
$line = fgets($fileHandle);
if (strlen($line) == 0) {
break;
}
$values = explode(',', $line);
$prodata[$counter]['dir_id'] = $this->request->params['named']['dirId'];
$prodata[$counter]['name'] = $dirName['Dir']['name'];
$prodata[$counter]['employee_id'] = $values[1];
$a = strptime($values[0], '%m/%d/%Y');
$timestamp = mktime(0, 0, 0, $a['tm_mon'] + 1, $a['tm_mday'], $a['tm_year'] + 1900);
$prodata[$counter]['qca_start'] = $timestamp;
$end = $timestamp + ($values[2] * 60);
$prodata[$counter]['qca_end'] = $end;
$prodata[$counter]['qca_tipcode'] = $values[3] * -1;
$prodata[$counter]['qca_durint'] = 0;
$prodata[$counter]['qca_durtel '] = 0;
$prodata[$counter]['qca_durend'] = 0;
$prodata[$counter]['qca_signal'] = 0;
$prodata[$counter]['qca_restart'] = 0;
$prodata[$counter]['qca_stop'] = 0;
$prodata[$counter]['qca_prevtipc'] = 0;
$prodata[$counter]['qca_respid'] = 0;
$prodata[$counter]['qca_lastq'] = 0;
$prodata[$counter]['qca_smskey'] = 0;
$prodata[$counter]['qca_telconta'] = 0;
$prodata[$counter]['qca_execuqoc'] = 0;
$counter++;
}
} else {
// file was just no good
echo 'fail';
exit;
}
if (count($prodata) > 0) {
$this->Qca->saveMany($prodata);
echo count($prodata);
}
}
First of all I will paste here a fragment from cakeapi under http://api.cakephp.org/class/controller about how autoRender works:
autoRender boolean
Set to true to automatically render the view after action logic.
So this:
$this->autoRender = false ;
will generally turns off rendering the view but just after action logic is done. So thats why you get the echos from your action logic. You can whether remove your echo's from your code to prevent showing them or try this schema,
if something is wrong:
$this->Session->setFlash('Error');
$this->redirect(array('action' => 'your_error_page'));
which will move you to ur error page with Error string as a Flash text, or when its all fine:
$this->Session->setFlash('Its fine dude!');
$this->redirect(array('action' => 'your_ok_page'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With