关于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