How to access router from model? #15435
Unanswered
Krzysiaczek
asked this question in
Q&A
Replies: 2 comments 1 reply
-
Try to use
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Following separation of concerns, Models should have no idea about the controller or action that has been invoked. That introduces a dependency that could cause trouble down the road. I think a better approach would be to have your model method accept an optional parameter. The action can then pass an argument to the model method when, and only if, it's necessary. Perhaps seeing the code of the method might help. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to access the method name from a Model to modify the query logic but it looks like it's not visible from here.
$this->router->getActionName()
works perfect in a controller or a view but when used in a model it's not visibleAccess to undefined property App\Models\Activities::router
When trying to call it with a domain name
\Phalcon\Mvc\Router::getActionName()
Fatal error: Uncaught Error: Non-static method Phalcon\Mvc\Router::getActionName() cannot be called statically
Any advice on how to fix it?
Beta Was this translation helpful? Give feedback.
All reactions