[eluser]herbageonion[/eluser]
Hi ztinger,
Here is the code from the Constructor and the Edit Method as requested, thanks for having a look.
Code:
class News extends Controller
{
function News()
{
parent::Controller();
// Load Helpers
$this->load->helper( array('url', 'date', 'text', 'form') );
// Load Libraries
$this->load->library( array('session', 'validation', 'image_lib') );
// Load Models
$this->load->model('news_model');
if ($this->session->userdata('logged_in') != true )
{
redirect('login', 'location');
}
}
function edit()
{
// Set Id
$id = $this->uri->segment(3);
$this->load->plugin('xinha');
// Set up View Vars
$data['title'] = $this->config->item('site_name') . " :: News & Information Items :: Edit";
$data['heading'] = $this->config->item('site_name');
$data['active'] = 'news';
$data['css'] = 'news.css';
$data['site_url'] = $this->config->item('base_url');
$data['news_item'] = $this->news_model->get_news_item($id);
$data['hidejquery'] = 'true';
$data['xinha_js'] = javascript_xihna(array('news_extract', 'news_text'));
// Check for sent form
$form_was_sent = $this->input->post('btn_edit_news');
if (!$form_was_sent)
{
$this->load->view('news_edit', $data);
}
else
{
$rules['news_header'] = "trim|required|max_length[255]|xss_clean";
$rules['userfile'] = "trim|xss_clean";
$rules['news_date'] = "trim|required|xss_clean";
$rules['news_extract'] = "trim|required|max_length[255]|xss_clean";
$rules['news_text'] = "trim|required|xss_clean";
$fields['news_header'] = 'Header';
$fields['userfile'] = 'Image';
$fields['news_date'] = 'Date';
$fields['news_extract'] = 'Extract';
$fields['news_text'] = 'Body';
$this->validation->set_rules($rules);
$this->validation->set_fields($fields);
if ($this->validation->run() == FALSE)
{
$this->load->view('news_edit', $data);
}
else
{
// Upload an Image
$file_config['upload_path'] = './uploads/';
$file_config['allowed_types'] = 'gif|jpg|png';
$file_config['max_size'] = '500';
$file_config['max_width'] = '1024';
$file_config['max_height'] = '768';
$this->load->library('upload', $file_config);
$file_data = $this->upload->data();
$header = $this->input->post('news_header');
$date = $this->input->post('news_date');
$extract = $this->input->post('news_extract');
$text = $this->input->post('news_text');
$image = $file_data['file_name'];
if ( ! $this->upload->do_upload())
{
die('<h2>Could not upload photo!</h2><p>'.$this->upload->display_errors().'</p>');
}
else
{
// Resize the Image
$img_config['image_library'] = 'GD';
$img_config['source_image'] = $file_data['full_path'];
$img_config['create_thumb'] = TRUE;
$img_config['maintain_ratio'] = TRUE;
$img_config['width'] = 100;
$img_config['height'] = 100;
$this->image_lib->initialize($img_config);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
else
{
$edit = $this->news_model->save_item($id, $header, $date, $extract, $text, $image);
}
}
}
}
}
}
Hi, Crimp, I'm uploading a jpg. I'll have a look through the libraries now I'll let ye know if I find anything to help.
Cheers