We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Detect controller instance

Hi, i use a micro application and i want detect current calling controller instance. i use before method

$app->before(function () use ($app) {

i know that i use


but getDefinition return path to class, not instance ;/ What can I do?



basically you can call dispatcher methods in any controller


i think this is what you need ? i am not 100% sure tho

edited Nov '17

thanks for answer but i can not use $this in function pointer in before() ;/

if i use $app->dispatcher->getActiveController() i get NULL

Important attention. i use LazyLoader

There is no dispatcher in micro app.

$app->getActiveHandler(); This doesn't return just controller instance?

edited Nov '17

getActiveHandler() return an array. First argument is LazyLoader(instance) and second parameter is the called method.

LazyLoader has getDefinition method but this method return class path(NOT INSTANCE!).

I can do it:

$lazyLoader->getDefinition() === App\Controller\TestController::class

but not

$lazyLoader->getDefinition() instanceof App\Controller\TestController // <- i want like this

I've just test it and that work fine without adding anything to catch ... What version of php / phalcon do you use ? Can you provide more code to check. resume examples for students

edited May '20

Thank you so much for problem solution. Maybe some update for code here? $app->getActiveHandler(); - works with LazyLoader.