Cakephp将html内容发送到空白视图

时间:2016-09-06 23:47:35

标签: cakephp

我正在使用Cakephp 2,我确实在动作中生成了html内容 我需要将html内容发送到空白视图。

我有控制器动作发送:

public function send()  {
        if ($this->request->is('get')) {
           $this->request->data['Doc']['value'] = 0.01;        
           $this->request->data['Doc']['name'] = 'OneName';
        }        
        if ($this->request->is('post')) {              
            echo $this->generate($this->request->data);              
        }       
    }

行动产生:

public function generate($data)   {    
    $html= new htmlGenerator($data);
    return $html->getOutput();
}

我有观看send.ctpgenerate.ctp

当我发送表单时,生成的html会保留在当前视图的顶部

如何发送到generate.ctp视图,传递this-> request->数据以生成操作?

1 个答案:

答案 0 :(得分:1)

这应该是这样的

public function send()  {       
    $this->autoRender = false;      

    if ($this->request->is('get')) {
       $this->request->data['Doc']['value'] = 0.01;        
       $this->request->data['Doc']['name'] = 'OneName';
       $this->render('path/to/your/send');
    }        

    if ($this->request->is('post')) {
        $this->set('generated',$this->generate($this->request->data));
        $this->render('path/to/your/generate');
    }       
}

然后在generate.ctp

<?php echo $generated ?>