Im working with a custom PHP MVC application
I retrieved a list of posts using this method:
MODELs: videos_model.php
class Index_Model extends Model {
public function fetchVideos(){
$stmt = $this->db->prepare("SELECT * FROM bv_videos");
$stmt->setFetchMode(PDO::FETCH_OBJ);
return $stmt->fetchAll();
}
}
CONTROLLERs : video.php class Index extends Controller {
public function index(){
$this->view->render('../../public/templates/header');
$this->view->Videos = $this->model->fetchVideos();
$this->view->render('index/index');
$this->view->render('../../public/templates/footer');
}
}
Views :
<div class="entry-header video_frame_description">
<h3><?php echo $value->title; ?></h3>
<p class="pull-left post-info">
<span class="cat-links hidden-xs">
<a href="<?php echo URL; ?>?cat=<?php echo $value->cat_id; ?>">
Category:
** HERE I WANT TO ADD CATEGORY NAME UNDER EACH POST **
</a>
</p>
</div>
In the view, I want to show the name of the video category under each post.
I created this function in the index class
public function get_video_category($cat_id){
$stmt = $this->db->prepare("SELECT * FROM bv_categories WHERE cat_id=?");
$stmt->execute(array($cat_id));
$stmt->setFetchMode(PDO::FETCH_OBJ);
$data = $stmt->fetch();
return $data->category;
}
And then in the Controller I added this line:
$this->view->video_category = $this->model->get_video_category();
And here the problem. What parameter should I pass the get_video_category() function??
Here are the tables structure im using:
bv_videos
CREATE TABLE IF NOT EXISTS
bv_videos(video_idint(11) NOT NULL AUTO_INCREMENT,
titlevarchar(255) NOT NULL,urltext NOT NULL,
cat_idint(11) NOT NULL,
date_addedint(11) NOT NULL,statusint(11) NOT NULL,
PRIMARY KEY (video_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ;
bv_categories
CREATE TABLE IF NOT EXISTS
bv_categories(cat_idint(11) NOT NULL AUTO_INCREMENT,categoryvarchar(100) NOT NULL,order_catint(11) NOT NULL DEFAULT '100', PRIMARY KEY (cat_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;