doujianwei8217 2013-09-29 19:40
浏览 37
已采纳

Yii重定向特定验证失败

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!'),
  • 写回答

1条回答 默认 最新

  • douhuang2282 2013-09-29 20:24
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度