4

ビューを必要としないコントローラーのアクションについては、次のようにレイアウトとテンプレートを無効にしています。

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

これがアクション全体です**

//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);
    }
}
4

1 に答える 1

7

まず最初に、autoRender の仕組みに関するhttp://api.cakephp.org/class/controllerの下の cakeapi のフラグメントをここに貼り付けます。

autoRender boolean true に設定すると、アクション ロジックの
にビューが自動的にレンダリングされます。

したがって、この:

 $this->autoRender = false ;

通常、ビューのレンダリングをオフにしますが、アクション ロジックが完了した直後です。これが、アクション ロジックからエコーを取得する理由です。コードからエコーを削除して表示されないようにするか、このスキーマを試すことができます。

何か問題がある場合:

$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'));
于 2012-09-24T12:28:53.233 に答える