Kisaragi
Kisaragi

Reputation: 2218

CodeIgniter loading views based on conditional

I would like to have a single controller generate multiple views depending on user input (in this case HTTP links) something like this:

public function video_home($ref_link)
{ 
     if ('user clicked link here'){

         $data = 'some stuff';

         $this->load->view('view1', $data)
        }
     elseif('2nd user clicked link here){
         $data = 'some stuff';

         $this->load->view('view2', $data)
        }

     $this->load->view('page with links here')
 }

I'm having a tough time trying to determine a way to get the ref link to pass to the conditionals. Any ideas?

Upvotes: 0

Views: 503

Answers (1)

Steve Bauman
Steve Bauman

Reputation: 8688

The $ref_link in your function would be a url parameter. So it would be accessed like this

www.example.com/video_home/link-one

public function video_home($ref_link){ 
     if ($ref_link == 'link-one'){

         $data = 'some stuff';

         $this->load->view('view1', $data);
     }
     else if($ref_link == 'link-two'){
         $data = 'some stuff';

         $this->load->view('view2', $data);
     }
     else{
         $this->load->view('page-links');
     }
}

Upvotes: 2

Related Questions