TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
checking the user was logined
  • how to escape duplicating code in each method to checking user login ?

    pulbic function add_post()
    {
    if(Auth::instance()->logged_in() == 0) {
    #redirect to main page
    Request::instance()->redirect('index');
    }
    ....

    public function delete_post()
    if(Auth::instance()->logged_in() == 0) {
    #redirect to main page
    Request::instance()->redirect('index');
    }
  • public function before()
    {
    if(Auth::instance()->logged_in() == 0)
    {
    //redirect to main page
    Request::instance()->redirect('index');
    }
    }
  • Thank`s i will try to use it )
  • You can use Auth::instance()->get_user() (it will also try to make autologon):

    if ($this->user = Auth::instance()->get_user())
    {
    // redirect or smth else
    }
  • Create an Admin controller, in this controller you'll check if the user is logged in.
    Then just extend this controller, this is how I do it.
  • it is make sense, when checking function place in __construct
  • Or in before().