Monday, July 1, 2013

Cakephp get view file content to a variable from controller

use Cake\View\View;

$html = ''; 
$this->autoRender = false; 
ob_start(); 

$view = new View($this->request);
# OR BELOW
$view = new View($this); 

$view->layout = null; 

/* controller name, a folder exists in views folder */ 
$view->viewPath = "FolderName"; 

/* variable send to view file */ 
$view->set("var", $var); 

$html .= $view->render("file_name"); 
/* a file exists in Views/FolderName/ folder/file_name.ctp */ 

ob_end_clean();

No comments:

Post a Comment