Welcome Guest, Not a member yet? Register   Sign In
master page, detail page, nested view?
#1

[eluser]w1n78[/eluser]
i created a controller that displays all records from the db. then i created another controller that displays details of 1 record. i'm trying to use the view for the 1 record with the display all view but i keep getting a cannot load class error. here is the code i'm working with.

view all controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller
{
public function __construct()
{
  parent::__construct();
  $this->load->model('movies');
}

public function index()
{
  $this->load->library('pagination');
  $config['base_url'] = site_url('home/page/');
  $config['total_rows'] = $this->db->get('movie')->num_rows();
  $this->pagination->initialize($config);
  
  $data['page_title'] = 'Welcome to iMoobis';
  
  $data['movies'] = $this->movies->page($this->pagination->per_page, $this->uri->segment(3));
  
  $this->load->view('templates/header', $data);
  $this->load->view('home', $data);
  $this->load->view('templates/footer');
}

view all view
Code:
<?php if ($movies): ?>
<h1>Latest Movies Added</h1>
&lt;?php echo $this->pagination->create_links(); ?&gt;

<ul>
&lt;?php foreach($movies as $movie): ?&gt;
   <li>
    &lt;?php echo $movie['title']; ?&gt;
    &lt;?php #echo $this->movie->detail($movie['movie_id']); ?&gt;
    &lt;?php #echo Movie::detail($movie['movie_id']); ?&gt;
   </li>
&lt;?php endforeach; ?&gt;
  </ul>
  &lt;?php echo $this->pagination->create_links(); ?&gt;
&lt;?php endif; ?&gt;

detail controller
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Movie extends CI_Controller
{
public function __construct()
{
  parent::__construct();
  $this->load->model('movies');
}



public function detail($movie_id)
{
  $data['movies'] = $this->movies->detail($movie_id);
  
  

   $this->load->view('movie/detail', $data);

  
}
}

detail view
Code:
&lt;?php if ($movies): ?&gt;
&lt;?php foreach ($movies as $movie): ?&gt;
  <h2>&lt;?php echo $movie['title']; ?&gt;</h2>
  <div class="movie-wrapper">
   <div class="image"><img src="&lt;?php echo $movie['medium_img']; ?&gt;" alt="movie cover" /></div>
   <div class="detail">
    &lt;?php if ($movie['actor']): ?&gt;
      <p><strong>Starring:</strong> &lt;?php echo Movie::parse_text($movie['actor']); ?&gt;</p>
    &lt;?php endif; ?&gt;
    
    &lt;?php if ($movie['director']): ?&gt;
      <p><strong>Director:</strong> &lt;?php echo Movie::parse_text($movie['director']); ?&gt;</p>
    &lt;?php endif; ?&gt;
    
    <p><strong>Audience Rating:</strong> &lt;?php echo $movie['audience_rating']; ?&gt;</p>
    <p><strong>Media Type:</strong> &lt;?php echo $movie['binding']; ?&gt;</p>
    
    &lt;?php if ($movie['studio']): ?&gt;
      <p><strong>Studio:</strong> &lt;?php echo $movie['studio']; ?&gt;</p>
    &lt;?php endif; ?&gt;
    
    &lt;?php if ($movie['currency_code'] == 'USD'): ?&gt;
      <p><strong>List Price:</strong> $&lt;?php echo $movie['list_price']; ?&gt;</p>
    &lt;?php endif; ?&gt;
    
    &lt;?php if ($movie['theatrical_release_date']): ?&gt;
      <p><strong>Theatrical Release Date:</strong> &lt;?php echo date('l, F d, Y',strtotime($movie['theatrical_release_date'])); ?&gt;</p>
    &lt;?php endif; ?&gt;
    
    &lt;?php if ($movie['release_date']): ?&gt;
      <p><strong>Release Date:</strong> &lt;?php echo date('l, F d, Y', strtotime($movie['release_date'])); ?&gt;</p>
    &lt;?php endif; ?&gt;
   </div>
  </div>
&lt;?php endforeach; ?&gt;
&lt;?php else: ?&gt;
<p>No movie found.</p>
&lt;?php endif; ?&gt;



the code works if i go to /foobar.com/movie/detail/record_id. but when i try to reuse it in the display all view or controller it says it can't find the detail(). so i tried to load it
Code:
$this->load->library('movie');

i get a can't load class error. not sure if i'm doing this correctly or is there another way to do it. i'm still a noob with MVC. thanks in advance.




Theme © iAndrew 2016 - Forum software by © MyBB