[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!