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

[eluser]garycocs[/eluser]
So have it up and running now, it was great practice learning the ins and outs of CI, next step will be another site and ajax.

So here it is:

http://www.karaokeyoutube.net/

This is my controller:
Code:
<?php

class Home extends Controller {

    var $base;
    var $css;
    
    function Home()
    {
        parent::Controller();    
        $this->load->scaffolding('videos');
        $this->load->model('home_model');
        $this->load->helper('form');
        $this->load->helper('url');    
        $this->load->library('validation');

        $this->validation->set_error_delimiters('<div class="error">', '</div>');

        $rules['name'] = "required";
        $rules['link'] = "callback_link_check";
        $rules['artist'] = "required";
        $rules['type'] = "required";
        $rules['age'] = "required";

        $this->validation->set_rules($rules);
                
        $fields['name'] = 'Name';
        $fields['link'] = 'YouTube Link';
        $fields['artist'] = 'Artist';
        $fields['type'] = "Type";
        $fields['age'] = 'Age';

        $this->validation->set_fields($fields);
        


    }
    
    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');    
        
        $data['queryheaderlist'] = $this->home_model->get_header_list();
        $data['querylatestlist'] = $this->home_model->get_latest_list();    
        $data['videolist'] = $this->home_model->get_video_list('10','0','0');
        $data['formtypearray'] = $this->home_model->form_type();
        $data['formagearray'] = $this->home_model->form_age();
        
        $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');    
        
        $data['queryheaderlist'] = $this->home_model->get_header_list();
        $data['querylatestlist'] = $this->home_model->get_latest_list();            
        $data['videolist'] = $this->home_model->get_video_list('10000',$this->uri->segment(3),'0');
        $data['formtypearray'] = $this->home_model->form_type();
        $data['formagearray'] = $this->home_model->form_age();
        
        $this->load->view('type_view',$data);
    }
    
    
    function addvideo()
    {
        
        if($this->validation->run() == FALSE) {
            
            $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');    

            $data['queryheaderlist'] = $this->home_model->get_header_list();
            $data['querylatestlist'] = $this->home_model->get_latest_list();                
            $data['videolist'] = $this->home_model->get_video_list('10','0','0');
            $data['formtypearray'] = $this->home_model->form_type();
            $data['formagearray'] = $this->home_model->form_age();

            $this->load->view('home_view',$data);
            
        } else {
            
            $link = $_POST['link'];
            $linkarray = explode("=", $link);        
            $link=$linkarray[1];
            $linkarray = explode("&", $link);        
            $link=$linkarray[0];
            $data = array(
                'name' => $_POST['name'],
                'link' => $link,
                'artist' => $_POST['artist'],
                'type' => $_POST['type'],
                'age' => $_POST['age']
                );
            $this->db->insert('videos', $data);

            $id = $this->db->insert_id();
            redirect('home/video/'.$id);            
        }
    }    
    
    function video()
    {        
        $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');    
        
        $data['queryheaderlist'] = $this->home_model->get_header_list();
        $data['querylatestlist'] = $this->home_model->get_latest_list();            
        $data['videolist'] = $this->home_model->get_video_list('1','0',$this->uri->segment(3));
        $data['formtypearray'] = $this->home_model->form_type();
        $data['formagearray'] = $this->home_model->form_age();
        
        $this->load->view('video_view',$data);
    }
    
    function link_check($str)
    {
        if (preg_match('/http:\/\/www\.youtube\.com\//', $str))
        {
            return TRUE;
        }
        else
        {
            $this->validation->set_message('link_check', 'The %s field must contain http://www.youtube.com/.....');
            return FALSE;
        }
    }
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */

As you can see there is some duplication in the code?

Is there ways of shortening this code?? Embedding one controller in another or something??

Maybe I should be putting more of the code in Home() ???

Thanks again for your help, it was great!


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