We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to access a function within a model

I need to access a funcion set in ControllerBase within a model :

<?php
use Phalcon\Mvc\Controller;
use Phalcon\Mvc\Dispatcher;

class ControllerBase extends Controller
{
    public function getAnswer()
    {
        return '42';
    }
...

<?php
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Relation;
class SomeModel extends Model
{
    public function initialize()
    {
        // i need the answer here !!
        ...


40.8k
Accepted
answer
edited Mar '14

Hi, two ways

ControllerBase::getAnswer();
$function = new ControllerBase();
$function->getAnswer();


7.9k

workd like a charm, thank you :)