How to render view in a variable inside controller in cakephp?

How to Render view in a variable inside Controller in CakePhp?

By using this code, you can fetch the html template content in a variable as a string.

You can also pass the parameters if required.

// Create an Instance of view
$view = new View($this, false);

// Passing the Needed Parameters

$view->set(compact('params1', $params1));
$view->set(compact('params2', $params2));

// Now load the template content as a string in variable,

$html = $view->render('ajax_product_template');

Leave a Comment