[eluser]garycocs[/eluser]
Starting to get it now slowly, the blog demo is a great help.
What do I do to shrink down the code here, this is an example of my controller for the site, you can see a fair bit of duplication in the code etc? What is the best way of getting rid of this?
Code:
<?php
class Home extends Controller {
var $base;
var $css;
function Home()
{
parent::Controller();
$this->load->scaffolding('videos');
$this->load->helper('form');
$this->load->helper('url');
}
function index()
{
$data['title'] = "Karaoke on YouTube - All your karaoke needs in one place!";
$data['base'] = $this->config->item('base_url');
$data['css'] = $this->config->item('css');
$this->db->select('type.name, videos.type, Count(videos.type) AS totaltype');
$this->db->join('type', 'type.id = videos.type');
$this->db->group_by('videos.type');
$data['queryheaderlist'] = $this->db->get('videos');
$this->db->select('type.name As typename, age.name As agename, videos.name, videos.id, videos.link, videos.artist, videos.type, videos.age');
$this->db->limit(10);
$this->db->order_by("id", "desc");
$this->db->join('type', 'type.id = videos.type');
$this->db->join('age', 'age.id = videos.age');
$data['videolist'] = $this->db->get('videos');
$typearray=array();
$this->db->select('id, name');
$query = $this->db->get('type');
foreach ($query->result() as $row) $typearray[$row->id] = $row->name;
$data['typearray'] = $typearray;
$agearray=array();
$this->db->select('id, name');
$query = $this->db->get('age');
foreach ($query->result() as $row) $agearray[$row->id] = $row->name;
$data['agearray'] = $agearray;
$this->load->view('home_view',$data);
}
function type()
{
$data['title'] = "Karaoke on YouTube - All your karaoke needs in one place!";
$data['base'] = $this->config->item('base_url');
$data['css'] = $this->config->item('css');
$this->db->select('type.name, videos.type, Count(videos.type) AS totaltype');
$this->db->join('type', 'type.id = videos.type');
$this->db->group_by('videos.type');
$data['queryheaderlist'] = $this->db->get('videos');
$this->db->select('type.name As typename, age.name As agename, videos.name, videos.id, videos.link, videos.artist, videos.type, videos.age');
$this->db->join('type', 'type.id = videos.type');
$this->db->join('age', 'age.id = videos.age');
$data['videolist'] = $this->db->get('videos');
$typearray=array();
$this->db->select('id, name');
$query = $this->db->get('type');
foreach ($query->result() as $row) $typearray[$row->id] = $row->name;
$data['typearray'] = $typearray;
$agearray=array();
$this->db->select('id, name');
$query = $this->db->get('age');
foreach ($query->result() as $row) $agearray[$row->id] = $row->name;
$data['agearray'] = $agearray;
$this->load->view('type_view',$data);
}
function addvideo()
{
$this->db->insert('videos', $_POST);
$id = $this->db->insert_id();
redirect('home/video/'.$id);
}
}