master page, detail page, nested view? - El Forum - 12-19-2011
[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>
<?php echo $this->pagination->create_links(); ?>
<ul>
<?php foreach($movies as $movie): ?>
<li>
<?php echo $movie['title']; ?>
<?php #echo $this->movie->detail($movie['movie_id']); ?>
<?php #echo Movie::detail($movie['movie_id']); ?>
</li>
<?php endforeach; ?>
</ul>
<?php echo $this->pagination->create_links(); ?>
<?php endif; ?>
detail controller
Code: <?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: <?php if ($movies): ?>
<?php foreach ($movies as $movie): ?>
<h2><?php echo $movie['title']; ?></h2>
<div class="movie-wrapper">
<div class="image"><img src="<?php echo $movie['medium_img']; ?>" alt="movie cover" /></div>
<div class="detail">
<?php if ($movie['actor']): ?>
<p><strong>Starring:</strong> <?php echo Movie::parse_text($movie['actor']); ?></p>
<?php endif; ?>
<?php if ($movie['director']): ?>
<p><strong>Director:</strong> <?php echo Movie::parse_text($movie['director']); ?></p>
<?php endif; ?>
<p><strong>Audience Rating:</strong> <?php echo $movie['audience_rating']; ?></p>
<p><strong>Media Type:</strong> <?php echo $movie['binding']; ?></p>
<?php if ($movie['studio']): ?>
<p><strong>Studio:</strong> <?php echo $movie['studio']; ?></p>
<?php endif; ?>
<?php if ($movie['currency_code'] == 'USD'): ?>
<p><strong>List Price:</strong> $<?php echo $movie['list_price']; ?></p>
<?php endif; ?>
<?php if ($movie['theatrical_release_date']): ?>
<p><strong>Theatrical Release Date:</strong> <?php echo date('l, F d, Y',strtotime($movie['theatrical_release_date'])); ?></p>
<?php endif; ?>
<?php if ($movie['release_date']): ?>
<p><strong>Release Date:</strong> <?php echo date('l, F d, Y', strtotime($movie['release_date'])); ?></p>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<p>No movie found.</p>
<?php endif; ?>
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.
|