doupian6118 2010-11-13 02:59
浏览 69
已采纳

在symfony中设置自定义错误重定向?

I am using Symfony 1.4 with Propel as ORM. I Have created a login system for my frontend page, where user can login and edit there account details.The page is set with Permission ="user" and Group ="user". But on loging in with a user which doesnot belong to this group, redirects to the symfonys default page(showing user dont have credentials to view this page). can these pages be customized and set our own custom messages..and how can we set custom error pages??

the code that i have used,

if($this->getContext()->getUser()->hasCredential("user"))
{
    $user_name=$this->getUser()->getGuardUser()->getUsername();
    $this->name=$user_name;
}
else
{
    $this->forward("userlogin", "error");
}

but i dont know this is the best way..

  • 写回答

2条回答 默认 最新

  • dph19153 2010-11-13 03:14
    关注

    You can change templates by overwriting them in Your app: apps/<appname>/modules/default/templates/error404Success.php

    To see list of possible templates look at: lib/vendor/symfony/lib/controller/default/templates/

    Now about credentials. At file apps/<appname>/config/settings.yml:

    # ...
    
    all:
      # ...
    
      .actions:
        login_module:           sfGuardAuth   # Change this to whatewer You want.
        login_action:           signin        # Change this to whatewer You want.
    
        error_404_module:       default       # Change this to whatewer You want.
        error_404_action:       error404      # Change this to whatewer You want.
    

    So if You want to change just template -- change just template. But if You want something more powerful -- change settings.yml and write custom code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部