Welcome Guest, Not a member yet? Register   Sign In
How to stop CI from continuing?
#11

[eluser]sophistry[/eluser]
hi mihalt,

i like the fact you are so confident. ("come on guys...") ;-)

as you may know, there are many ways to accomplish a login check. putting logic and view loading in the constructor of a "superclass" strikes me as a little bit unconventional. also, there are certain things that just don't work in a CI constructor (i recall something that simply doesn't work in PHP4, but i can't find it right now). additionally with view loading and the third parameter you have to keep those class variables and you end up with the same variable scoping issue discussed in this other recent thread: http://ellislab.com/forums/viewthread/97450/

since we are genially discussing the merits of each approach...
hooks: load a lib at proper point in CI core code, access lib anywhere after that point - easy, but results in obfuscated/invisible code.

_remap(): handle all logic in one function right at the root of the "superclass". you don't have to worry about scoping variables because except for the _remap() code everything else is like a "normal" CI code execution.

logic and view loading in constructor of "superclass": handles all logic at root of superclass - have to build infrastructure in derived classes to handle and access data and logic results of the "superclass" constructor.

your thoughts on that summary? did i hit every point? did i miss any other techniques?
#12

[eluser]Phil Sturgeon[/eluser]
All good replies but im not going to get into what you are trying to do as everyone else has that covered!

From a purely technical point of view, the best way to end CI and show output so far would be to make a helper file that basically just runs:

Code:
exit($this->output->get_output());

That would stop it in its tracks ^_^
#13

[eluser]nwp2005[/eluser]
[quote author="Phil Sturgeon" date="1227212944"]All good replies but im not going to get into what you are trying to do as everyone else has that covered!

From a purely technical point of view, the best way to end CI and show output so far would be to make a helper file that basically just runs:

Code:
exit($this->output->get_output());

That would stop it in its tracks ^_^[/quote]

The problem with this for me is that I would like to send an HTTP status code (HTTP/1.1 401 Unauthorized) and when I use exit it ignores my header and sets it to 200 OK.

In the past I have put a call to an authentication library in the constructor of my controller like this:

Code:
$this->myauth->require_login();

the require_login() function would redirect to a login page and code execution would stop. But now I am trying to use ExtJS and I want to send an XML error but I also want to send an HTTP status code so I can use the XMLReader loadexception event. In my constructor I want to do something like this if authentication fails:

Code:
$this->output->set_header("HTTP/1.1 401 Unauthorized");
$this->output->set_header('Content-type: text/xml');
$data = '<error><error-message>Session expired</error-message></error>";
$this->load->view('template/json', $data);
exit();

But when I use exit() or die() the header status code changes to 200. If I don't include exit() or die() then code execution continues.




Theme © iAndrew 2016 - Forum software by © MyBB