Question

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().

Was it helpful?

Solution

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.

OTHER TIPS

Its a bad practice, because after die no code will execute. Suppose you have some code (Hooks) to be executed after loading of view it will not execute.

If you are using die() mean there should be some reason for that. Can you please tell me why you want to use that at the end of views in CI?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top