0

I am pretty new to codeigniter. I am facing an inconvenient issue. I have code like this in profile.php (controller):

 public function edit()
    {
        $post = $this->input->post();

        if($post)
        {
            //checking session username (if logged in)
            if(isset($this->session->userdata('username') && !empty($this->session->userdata('username')))
            {

            }else{
             /***************************REFERENCE DIFFERENT CONTROLLER HERE*********/
                $this->load->view('login');    //should I write membership/index?
            }

        }else{

        }

    }

So I check if user logged in, if yes, code executes. if not, I wish to redirect to a function in different controller i.e. membership.php and it is the index() function of that controller. How can I reference that?

1
  • use helper function redirect Commented Mar 15, 2013 at 6:36

2 Answers 2

1

use redirect("membership/index"); for redirection in codeigniter

Sign up to request clarification or add additional context in comments.

Comments

0

Use redirect variable

     public function edit()
{
    $post = $this->input->post();

    if($post)
    {
        //checking session username (if logged in)
        if(isset($this->session->userdata('username') && !empty($this->session->userdata('username')))
        {
             redirect('membership');
        }else{
         /***************************REFERENCE DIFFERENT CONTROLLER HERE*********/
            $this->load->view('login');    //should I write membership/index?
              redirect('membership'); // you can use this where u want to refrence/redirect
        }

    }else{

    }

}

1 Comment

Thank you. Another solution is to create a class and extend it. That is much cleaner than redirect. Just for future reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.