普通网友 2013-05-08 10:08
浏览 44
已采纳

在CodeIgniter的“视图”末尾添加die()是不好的做法吗? [关闭]

In order to make things right and prevent CodeIgniter from loading another views after a loaded view I needed to added die() at the end of views (footer). Is this a bad practice and Will this cause any problems?

The code is a little bit large to be posted here but I can say that there is an if statement which loads a view and by default the function loads another view. So when if statement gets passed, It loads the defined view and then the function loads the default view after it. I can use die() inside my controller but it gives me a blank page meaning that die() got executed before loading the view. and I can't neither use redirect().

  • 写回答

3条回答 默认 最新

  • duanjiong5686 2013-05-08 10:18
    关注

    It is a bad practice. The end of the method at controller level is not the actual end of the execution of the code related to the request. Codeignitor has a setup of loading a controller and then calling its method, and then executing other code after the method execution has finished.

    Apart from the CodeIgnitor internal code, there are hooks

    http://ellislab.com/codeigniter/user-guide/general/hooks.html

    if you have defined "post controller" hooks, which get executed after the controller method has finished,those will not be executed if you put die in your code.

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

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP