Rendering controller to a different view in CakePHP

后端 未结 7 1081
长发绾君心
长发绾君心 2021-02-01 16:10

Is there a way to render a controller to a different view then normal? I\'m trying to pass some data from the controller to a non-default view. Meaning my controller is called:<

7条回答
  •  时光说笑
    2021-02-01 16:48

    class StocksRealtimeController extends AppController
    {
       var $uses = 'StockRealtime';
    
       function index( )
       {
         $this->layout     = NULL;
         $this->autoRender = false;
    
         $this->set('stocksRT', $this->StockRealtime->find('all'));
    
         return $this -> render('/TestView/index');
         /*
            $this -> render('/TestView/index');
            Here 'TestView' must be a Folder named same as "public $name" variable value        
            in Controller and an "index.ctp" must be situated under TestView Folder.
           'index'
         */
       }
    }
    

    Give it a try, return 'KEYWORD' must be there to render view page successfully. Sorry about 2nd question as i didn't get it. According to CakePHP, variable [stocksTR] which is set using $this -> set( ) , also will be available at manually render view page [ 'index.ctp' ].

提交回复
热议问题