CakePHP: A cheeky way of using a helper in a controller

In CakePHP sometimes you need to use a helper, such as the HtmlHelper in a controller. For example I needed to build links in a HTML email within a controller only (no view) action


class SomeController extends AppController {
    function index() {
        $view = new View($this);
        $Html = $view->loadHelper('Html');
        debug($html->link('I Am Kieran', ''));

Author: Kieran Barnes

Kieran is a PHP developer with 15 years commercial experience. Specialist in WordPress, CakePHP, CubeCart and all things PHP.