Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to call a helper function in a controller

Hi I have created a file Helper.php in the helper folder it contains the code:

class Helper extends Phalcon\Mvc\User\Component

    public function GetMessage($code)

        $message = $this->modelsManager
            ->from(['message' => 'SystemMessage'])
            ->where('message.msg_code = :msg_code:', 
                ['msg_code' => $code])

            return $message;

I have added to loader.php: $config->application->helpersDir,

and to config.php: 'helpersDir' => APP_PATH . '/helpers/',

How do I actually now call the function with in a controller I have tried quite a few ways without success.

Secondly is this the best way to do this? Is there a better recommended way of setting up this global function? (in terms of best practice)



Ok, got it working now:

$this->view->disable(); $msg = new Helper; $message = $msg->GetMessage('ER_CARD_DECLINED');