Welcome Guest, Not a member yet? Register   Sign In
Tiny tweak that's saved me a lot of time
#1

[eluser]mattalexx[/eluser]
I extend the core controller and add a method called internal_redirect. If you only use this everywhere you are redirecting to another method within the same controller, you will make your controller a lot more portable and rename-able.

Here 'tis:

Code:
class MY_Controller extends Controller {

   function MY_Controller() {
      parent::Controller();
   }

   function internal_redirect($url) {
      redirect($this->uri->segment(1).'/'.$url);
   }

}
#2

[eluser]Colin Williams[/eluser]
Quote:If you only use this everywhere you are redirecting to another method within the same controller

Another method in the same controller? Um, why not just call $this->other_method(), and exit if needed? I do this all the time.

Code:
class User extends Controller {

  function User()
  {
    parent::Controller();
    $this->load->library('users');
  }

  function index()
  {
    if ($this->users->check_access())
    {
      $this->dashboard();
    }
    else
    {
      $this->login();
    }
  }

  function logout()
  {
    $this->users->logout();
    $this->index();
  }

}
#3

[eluser]mattalexx[/eluser]
Boy do I feel dumb. Well, thanks for that.
#4

[eluser]Colin Williams[/eluser]
Smile This is why I like to encourage writing documentation as you build because you catch yourself writing something like "call another method in the same controller" and you slap your forehead and go about it in a more clear way.
#5

[eluser]mattalexx[/eluser]
Actually come to think about it, Controller::internal_redirect does have a place, in that it resets the POST and changes the URL, which is useful after say processing a form.




Theme © iAndrew 2016 - Forum software by © MyBB