gpt4 book ai didi

cakephp render-false 操作仍然回显 html 模板

转载 作者:行者123 更新时间:2023-12-02 21:05:04 24 4
gpt4 key购买 nike

对于 Controller 中不需要 View 的操作,我将禁用布局和模板,如下所示:

$this->autoRender = false;

一切都很好。然而,在同一操作中,我会回显“通过”或“失败”来表明我对结果的看法。问题是一堆文本也被回显:(我的“失败”或“通过”在最后)

 <!--
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> ....

这被重复了 8 到 9 次。

我怎样才能摆脱这个问题,以便只回显我的“通过”或“失败”?你能帮忙吗?

我已经尝试过

$this->layout = false; and
$this->render(false);

非常感谢。

更新:**刚刚注意到它还无缘无故地回响了一堆 javascrip 代码(删除了 < 以粘贴到此处)例如: pre class="cake-error"a href="javascript:void(0);"onclick="document.getElementById('cakeErr5035af14add0c-trace').style.display = (document.getElemen..

这就是整个 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);
}
}

最佳答案

首先,我将在 http://api.cakephp.org/class/controller 下粘贴来自 cakeapi 的片段。关于 autoRender 的工作原理:

自动渲染 bool 值
设置为 true 可以操作逻辑之后自动渲染 View 。

所以这个:

 $this->autoRender = false ;

通常会在操作逻辑完成后关闭渲染 View 。这就是为什么你会从你的行动逻辑中得到回应。您可以从代码中删除回显以防止显示它们,也可以尝试此架构,

如果出现问题:

$this->Session->setFlash('Error');
$this->redirect(array('action' => 'your_error_page'));

这会将您移至错误页面,其中错误字符串为 Flash 文本,或者当一切正常时:

$this->Session->setFlash('Its fine dude!');
$this->redirect(array('action' => 'your_ok_page'));

关于cakephp render-false 操作仍然回显 html 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12062097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com