Welcome Guest, Not a member yet? Register   Sign In
Stopping workflow
#1

[eluser]Dark$hadow[/eluser]
Hi all,

First of all, sorry for my english, I'm french...

I use hooks at 'post_controller_constructor' level to control user is logged in before do any action and I would like to be able to stop the workflow immediately if user isn't logged.
I know it's possible to do a redirection but it's not what I want (because of ajax requests).

Here is my code (last instruction doesn't work):
Code:
if ($this->CI->input->post('method') == 'ajax') {
                $this->CI->output->set_header("HTTP/1.1 403 Forbidden");
                $this->CI->output->_display(); <--- STOP THERE AND RENDER
            }



I simply search a way to say "stop there and render immediately without passing in the called controller".

Many thanks by advice for your answers.

Dark.
#2

[eluser]Buso[/eluser]
from the userguide:

Quote:post_controller
Called immediately after your controller is fully executed.

I don't think that will give you any security (if that is what you are after).

You should think about using a pre_controller hook, or check for permissions inside the controller constructor.

I use this function to stop worflow + display output, but I execute it inside a controller:

Code:
public function _end() {
        
        log_message('debug', get_class($this) . '->' . __FUNCTION__ . '()');
        
        $BM  =& load_class('Benchmark');
        $EXT =& load_class('Hooks');
        $OUT =& load_class('Output');
        $RTR =& load_class('Router');
        
        $class  = $RTR->fetch_class();
        $method = $RTR->fetch_method();
        
        // Mark a benchmark end point
        $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
        
        /*
         * ------------------------------------------------------
         *  Is there a "post_controller" hook?
         * ------------------------------------------------------
         */
        $EXT->_call_hook('post_controller');
        
        /*
         * ------------------------------------------------------
         *  Send the final rendered output to the browser
         * ------------------------------------------------------
         */
        
        if ($EXT->_call_hook('display_override') === FALSE)
        {
            $OUT->_display();
        }
        
        /*
         * ------------------------------------------------------
         *  Is there a "post_system" hook?
         * ------------------------------------------------------
         */
        $EXT->_call_hook('post_system');
        
        /*
         * ------------------------------------------------------
         *  Close the DB connection if one exists
         * ------------------------------------------------------
         */
        
        if (class_exists('CI_DB') AND isset($this->CI->db))
        {
            $this->CI->db->close();
        }
        
        exit;

}
#3

[eluser]danmontgomery[/eluser]
He's using post_controller_constructor, not post_controller.

There's no reason you can't do what you're already doing, just add an exit() after _display(). You'll lost the post_system hook this way, and CI calls db->close() after _display, so if you're using persistent connections you would want to manually close those.
#4

[eluser]Buso[/eluser]
My mistake Smile
#5

[eluser]Dark$hadow[/eluser]
Wonderful noctrum solutions seems to work like a charm Smile

Here is the final code:
Code:
if ($this->CI->input->post('method') == 'ajax') {
                $this->CI->output->set_header("HTTP/1.1 403 Forbidden");
                $this->CI->output->_display();
                exit();
            }




Theme © iAndrew 2016 - Forum software by © MyBB