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?



32.7k
    $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.



15.0k
edited Sep '14

Ok what options do I have to stop validation



18.6k

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).