문제

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