Hello,
I am implementing DRY (Don't repeat yourself) as much as possible, which is why I have made seperate functions from repetitive tasks in my Controllers.
To create a "home" for these methods, I have created some Components classes, that each extend \Phalcon\Mvc\User\Component.
I can either:
-
Call these component methods statically from the Controllers, using ComponentName::methodname(), provided I have declared the method as static in the Component of course... or:
- Make those Component methods non-static and instantiate the Component class first, before calling its methods. So like this: $test = new ComponentName; $result = $test->methodname();
The first option has my preference, but then I run into not being able to use the db connection from the Dependency Injector. Which I would call by using $this->di->get('db'); It doesn't work of course, because we cannot use $this without an object context.
Is there no easy way around this? Otherwise I have to go for method 2 and refactor much of my code?
I know this is probably more OO related stuff, but it stops me in embracing Phalcon to the fullest, which is why I post this question here.
Thanks! Alex