emersonthis emersonthis - 2 years ago 73
PHP Question

CakePHP: How to use a view element inside of a controller

I'm trying to figure out how to use one of my view elements inside of a controller...

I know, I know: "Don't do that!" (99% of the time this is the correct answer)

But I think I actually have a good reason. The action is handling an AJAX request which returns markup. The returned markup is a list which I display everywhere else using an element. So in an effort to keep my code DRY, I think it's appropriate to do this here.

Is this possible?

Answer Source


$view = new View($this, false);
$content = $view->element('my-element', $params);



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download