Search code examples
phpcodeigniter-2codeigniter-3

Passing segment data from view to controller and then to a new view


Hi i am using Codeigniter(i am fairly new) and i have a problem displaying data(actually a path from the database) to View B but lets take it from the beggining. I am making a cinema web page and I want a user to click on a link and then get the appropriate redirect to another link which will display the movie that clicked. I am getting the movie name from the database and manage to send it to the Controller B as a parameter and get the image path that i want to display in order to show the picture. But the web page does not show the picture although the path is already sent(i have checked it on Firefox fire bug and to a blank page just to make sure the the path is sent) Btw when i load the page the method and parameter appears on the url but when i delete the parameter and the method from the url and hit enter the path works perfectly displaying the image. Any help?

ps I am a rookie

This is from view a

<div class="movie__images">
   <a href="<?php echo base_url()?>movie_page_full/get_user_click_info/<?php echo $movie_data[6]->title ?>" class="movie-beta__link">
     <img alt='' src=<?php echo $now1 ?>>
   </a>
</div>

This is from controller b

public function get_user_click_info(){

    $this->load->model('movie_page_full_model');

    $decoded_movie_name =  $this->uri->segment(3);


    $query_data = $this->movie_page_full_model->get_single_movie_data($decoded_movie_name);

    $data['path'] = $query_data[0]->path;



    $this->load->view('templates/header');
    $this->load->view('Home/view_movie_page_full',$data);
    $this->load->view('templates/footer_movie_page_full');
}

This is from the view b where i send the path from the controller b

      <div class="col-sm-4 col-md-3 movie-mobile">
              <div class="movie__images">
                  <img alt="" src=<?php echo $path ?>>
              </div>
       </div>

A proof that the path is send to the HTML code but does not show it

The url (Gravity is the name of the movie)


Solution

  • I found the answer to my question. I discovered that when i was changing controllers and loading the image, the path was displaying properly but actually it was missing the full url as i was leaving from the homepage that i set as the base url so the only thing that i had to do, was to use the variable that contains the path inside the codeigniter base url. Base url actually appends the rest of missing part. Below is the correct code block.

        <div class="col-sm-4 col-md-3 movie-mobile">
              <div class="movie__images">
                  <img alt="" src=<?php echo base_url($path)?>>
              </div>
       </div>