Welcome Guest, Not a member yet? Register   Sign In
How to reroute or stop a method from executing without redirect
#1

[eluser]n0xie[/eluser]
I don't think what I want is possible but here goes anyway.

I have to add a maintenance notice to some parts of a website. The application is rather complex so I want to make it as unobtrusive as possible. To do this I don't want to add checks every method in every controller nor do I wish to use redirects since the application relies heavily on SEO and a 302 redirect gets penalized by google.

Instead I opted for this:

Code:
// MY_Controller
function MY_Controller()
{
  parent::Controller();
  $this->check_maintenance($this->router->class);
}

private function check_maintenance($current_class)
{
  // check if current class is under maintenance. If so show a maintenance notice
}

This is fairly straightforward and works but after the maintenance view is loaded, it returns to the Controller and then executes the called method. This is of course logical, but how do I stop this from happening. I tried overwriting the $this->router->method, but as far as I can tell this doesn't work as the method is already called.

So basically my question is, how do I stop the method from executing from within the base controller's construct without having to add checks in the called class. I would have guessed a simple 'exit()' would work, but then the output class is never called and so no output is given at all (so no 'maintenance page' just a blank white page.)
#2

[eluser]Twisted1919[/eluser]
Maybe this will help
Code:
class MY_Controller extends Controller{

public function __construct()
    {
    parent::Controller();
    $this->get_site_status();
        }


[...]
private function get_site_status()
    {
    if($this->config->item('site_online') == FALSE )
        {
        if($this->uri->segment(1) != 'adm')
            {
            $this->load->library('exceptions');
            $heading = $this->config->item('site_name') ;
            $message = $this->config->item('site_offline_message') ;
            echo $this->exceptions->show_error($heading, $message, 'maintenance', 200);
            exit;        
            }    
        
        }
    }
[...]
}
#3

[eluser]n0xie[/eluser]
After re-reading my own post I realized something.

Solution is to bypass the Output class:
Code:
$output = $this->load->view('maintenance_view',NULL,TRUE);
echo $output;
exit();
#4

[eluser]Clooner[/eluser]
Try overwriting the function _remap($method) in your controller. That is the way to go.
#5

[eluser]n0xie[/eluser]
[quote author="clooner" date="1255542415"]Try overwriting the function _remap($method) in your controller. That is the way to go.[/quote]
Like I said, I don't want to add or edit any of the existing Controllers.
#6

[eluser]Clooner[/eluser]
You could overwrite the _remap in your My_Controller




Theme © iAndrew 2016 - Forum software by © MyBB