Welcome Guest, Not a member yet? Register   Sign In
Basic Form Help
#5

[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);
    }    
}


Messages In This Thread
Basic Form Help - by El Forum - 08-03-2009, 08:27 AM
Basic Form Help - by El Forum - 08-03-2009, 08:57 AM
Basic Form Help - by El Forum - 08-03-2009, 08:59 AM
Basic Form Help - by El Forum - 08-03-2009, 09:01 AM
Basic Form Help - by El Forum - 08-03-2009, 11:43 AM
Basic Form Help - by El Forum - 08-03-2009, 01:36 PM
Basic Form Help - by El Forum - 08-04-2009, 04:39 PM
Basic Form Help - by El Forum - 08-04-2009, 07:41 PM
Basic Form Help - by El Forum - 08-05-2009, 07:14 AM
Basic Form Help - by El Forum - 08-05-2009, 09:37 AM
Basic Form Help - by El Forum - 08-05-2009, 10:18 AM
Basic Form Help - by El Forum - 08-05-2009, 11:11 AM
Basic Form Help - by El Forum - 08-05-2009, 12:23 PM
Basic Form Help - by El Forum - 08-05-2009, 12:41 PM
Basic Form Help - by El Forum - 08-05-2009, 01:01 PM
Basic Form Help - by El Forum - 08-05-2009, 01:09 PM
Basic Form Help - by El Forum - 08-11-2009, 07:51 AM
Basic Form Help - by El Forum - 08-11-2009, 08:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB