關於CI的快速問題。在codeigniter中使用上傳類 - 模型還是控制器?
我有一個視圖與表格,幾個文本輸入字段和文件上傳。 我希望能夠從文本字段獲取輸入,將其保存到數據庫,然後上載圖像。
我已經有一個控制器上傳代碼來實現這一點,如果上傳成功,我型號進行調用,更新數據庫。
這是「最佳實踐」還是確實是一種可接受的方式?或者應該將文件上傳放入模型中。有關係嗎?
本質上我的代碼是:
function edit_category()
{
$config['upload_path'] = 'images/category/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '1000';
$config['max_width'] = '300';
$config['max_height'] = '300';
$this->load->library('upload', $config);
if(!$this->upload->do_upload())
{
$this->session->set_flashdata('status', $this->upload->display_errors());
redirect('admin/category/edit/'.$this->input->post('catID'), 'location');
}
else /*no errors, upload is successful..*/
{
$fInfo = $this->upload->data();
//$this->_createThumbnail($fInfo['file_name']);
//process form POST data.
$data = array(
'catName' => $this->input->post('catName'),
'catDesc' => $this->input->post('catDesc'),
'catImage' => $fInfo['file_name']
);
/* update the database */
$category = $this->category_model->edit_category($data, $this->input->post('catID'));
我想問一個問題。如何將上傳錯誤或上傳數據從模型返回給控制器,以便將其顯示在視圖中?有沒有使用flashdata的另一種方法嗎? – Lykos 2014-12-19 08:36:50