I have this validation rule in an user table that makes sure user email is unique. Now I don't want to skip this validation, but want to give an option to the user to choose the existing user data and insert relevant data to another relation table. Is there any way to catch if this particular validation rule fails and then redirect to another controller/action, but I don't want to redirect when any other rule fails.

array('email','unique','message'=>'{attribute}:{value} already exists!'),
有帮助吗?

解决方案

Yes ...

Oh, are you asking how to do the above? ;-)

In your controller where you save your model, if saving doesn't work, check for errors for that particular attribute:

$this->getError(<attributeName>);

If the message matches your error above, redirect in your controller. Otherwise, handle the errors as you normally do

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top