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

getActionName() in model

Hello,

I need to stop 1 of validations in model, but I need to know the current action name, so is it possible to getActionName() somehow?



51.2k
    $this->getDI()->get('dispatcher')->getActionName();

But honestly, that's a bad programming habbit. Models should be models, and that's it. You should find another solution for injecting the action name if you really want to validate that.



25.0k
edited Sep '14

Ok what options do I have to stop validation



33.8k

1) For your getActionName() (in your controller/action):

$this->view->setVar('myVar', $this->dispatcher->getActionName());

2) To stop a validation (or don't do it), just don't add it to the validator. Do a class that extends from Validation, and there create a method that adds some validators depending of your action name. Later, just call it with $this->validator->myValidation() (you could send a param with the variable described before).