douyong1885 2014-10-16 06:38
浏览 348
已采纳

未登录时,AuthComponent成功重定向到登录页面,但某些控制器失败并显示空白页面?

I had a site in the local windows system made in cakephp. When I uploaded it to server (linux environment) the site works fine but some controllers are showing blank pages. The site works fine in local system though.

For example, when I type http://example.com/dashboard it correctly redirects back to login page but when I type http://example.com/settings it shows only blank page.

I have tried clearing tmp folder caches, renaming the controller to something else like Books, changing debug level, but neither any error shows up nor the page loads correctly. But error shows up on other pages if I make a mistake. So error reporting is working fine.

If I allow the controller action in the beforeFilter() using $this->Auth->allow() the page loads up but the codes like AuthComponenet::user('name') return empty values.

So the problem seems to be in the AuthComponenet which is successfully redirecting some pages to login and not redirecting some. And for those pages (or controllers) that it doesn't redirect it shows only a blank page irrespective of whether I am logged in or not. So what can be the possible error? The CakePHP version is 2.5.5.

Following is the AuthComponent initializing code in the AppController:

public $components = array(
    'Auth' => array(
                'loginAction' => array(
                                    'controller' => 'members',
                                    'action' => 'login'
                                ),
                'authError' => 'Did you really think you are allowed to see that?',
                'authenticate' => array(
                                    'Form' => array(
                                        'userModel' => 'Member',
                                        'fields' => array('username' => 'name','password'=>'password'),
                                        'passwordHasher' => array(
                                                            'className' => 'Simple',
                                                            'hashType' => 'md5'
                                                        )
                                    )
                                )
                ),
    'Session',
    //'DebugKit.Toolbar'
);
  • 写回答

2条回答 默认 最新

  • dtsfnyay300457 2014-10-16 09:10
    关注

    Behold the height of my stupidity...

    So as it seemed there was some problem in the AuthComponent I tried var_dumping from the AuthComponent library codes step by step to detect the problem. While doing so I noticed a peculiar thing. When the text from var_dump() is output every controller behaved the same and returned a blank page. So it became apparent that the problem was due to presence of blank spaces somewhere in the controller, because in the view source mode also one blank line was getting output:

    enter image description here

    But I had thoroughly checked and made sure there were no blank spaces or lines after the end of the Controller code. Even there were no closing ?> php tags at the end to cause the error. So where could it be? Behold my stupidity that I had an empty line just above the beginning of the Controller codes .

    enter image description here

    Clearing the empty line in the beginning solved the problem. But alas! such a silly thing took out 3 hrs of my useless time :D

    Moral of the story:

    • Make sure to check both beginning and end of files for empty space and lines when deploying code in linux systems.

    • Try some light code coloring schemes in the editor while debugging so that empty lines can be easily visible :D

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

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝