CakePHP 2.0控制器渲染不能一直工作

时间:2012-03-06 22:15:34

标签: cakephp cakephp-2.0

我有一个搜索控制器,它将根据应显示的报告类型查找值并呈现特定视图。发生了一件奇怪的事情。当我发出$ this->渲染时,不会渲染报表视图。始终会呈现“catch all”重定向行...代码如下:

  

public function admin_printReport(){

if (isset($this->request->data['Reports'])) {

    $nons = $this->request->data['Reports'];

    $res = array();

    // lets lookup the noncons.....       
    foreach ($nons as $dat=>$vdat) {

        // skip the ones that are not checked 
        if ($vdat == 0) {
            continue;
        }

        // this is the temporary array that holds all of the selected report numbers          >             $res[] = $dat;

    }

    $this->loadModel('Noncon');       
    $this->Noncon->recursion = 0; 
    $results = $this->Noncon->find('all', array('conditions'=>array('Noncon.id'=>$res)));
    $this->set('results', $results);  

    // lets do the selection now...
    if (isset($this->request->data['PS'])) {  
        // Print summary
        $this->render('summary', 'print');
    } elseif (isset($this->request->data['PD'])) { 
        // Print detail 
        $this->render('detail', 'print');
    } elseif (isset($this->request->data['PDH'])) { 
        // Print detail with history 
        $this->render('detailhistory', 'print');
    }
} 

// catch all if the render does not work....
$this->redirect(array('controller'=>'noncons', 'action'=>'search','admin'=>true)); 
     

}

任何想法?

2 个答案:

答案 0 :(得分:1)

我只是想出来......

对于每个$ this->渲染,添加返回。例如:

  

返回$ this->渲染('summary','print');

答案 1 :(得分:0)

我刚刚添加了类似的问题。

在具有ajax提交的控制器中,它没有提交渲染。

$this->render($viewName, 'ajax');

使用return没有帮助。

问题在于我添加了

$this->render('add');

在控制器的末尾,虽然没有必要,因为控制器名称是 add 并且autoRender是默认值(true表示自动呈现具有相同控制器名称的视图)。 / p>

希望这有助于其他人。