Welcome Guest, Not a member yet? Register   Sign In
A view() to die() for
#7

[eluser]slowgary[/eluser]
It unfortunately doesn't achieve the desired behavior either, since the desired behavior would be to stop the index() method from executing in the admin controller, while still outputting the view outputting the view from the constructor of its parent class.

Ultimately, I solved it by creating a Login controller and a redirect, in addition to the SecureController base class.

Something like this:
Code:
class SecureController extends Controller
{
     function SecureController()
     {
          if(strtolower(get_class($this)) != 'login' AND $this->is_logged_in() === FALSE)
          {
               $this->session->set_userdata('redirect', $this->uri->uri_string());
               redirect('/login');
          }
     }
}

class Login extends SecureController
{
     function _remap()
     {
          //if post data, check login

          //if valid credentials, $this->session->set_userdata('logged_in')

          // else send to login view
     }
}

class Admin extends SecureController
{
     function index()
     {
          //this function will only run if the user is logged in.
     }
}


Messages In This Thread
A view() to die() for - by El Forum - 08-31-2010, 10:42 AM
A view() to die() for - by El Forum - 08-31-2010, 11:10 AM
A view() to die() for - by El Forum - 08-31-2010, 11:19 AM
A view() to die() for - by El Forum - 09-01-2010, 10:06 AM
A view() to die() for - by El Forum - 09-01-2010, 10:11 AM
A view() to die() for - by El Forum - 09-01-2010, 10:31 AM
A view() to die() for - by El Forum - 09-01-2010, 04:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB