Quantcast
Channel: Tiplite » CakePHP
Viewing all articles
Browse latest Browse all 5

Quick tip: Get element content within the controller in CakePHP

$
0
0

This is an easy quick tip to able able to get an element’s content from within a controller in CakePHP 1.2 or 1.3. The trick is simple you just need an instance from View class to be able to use its element function within the controller. To do this use the following code inside your action:

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

$params is an optional parameters array which is sent to the element to be used as variables. You can also use $view->set() just as you use $this->set() in your controller.

Now as you know it, how you intend to use? or what was the situation where you needed to use something like this?


Viewing all articles
Browse latest Browse all 5

Trending Articles