[eluser]Felipe Deitos[/eluser]
Hi guys!
I am doing my first site in CI to a company.
CI is the best thing i ever worked with... i am trying to keep everything as clean as possible and do everything with good practices.
I am developing my first project in CI to a company.
I got a lot of thing already done, the one i like to discuss here is the news system...
1) First thing i want to know if my db structure is a good way of doing this...
I store the new in one and in other table as many images i want...
Ex:
(table)news
-id
-title
-content
(table)news_imgs
-id
-new_id
-img
This is a good table structure to store how many pictures i want in one new?
There are better ways to do this?
2) Second thing is my code... i used the image manipulation for the first time, is working everything fine but as i said above i want to do the best i can...
Controller:
Code:
public function image_upload()
{
//if the user is admin Just to u guys know
$this->is_admin();
$this->load->model('dicas_model');
//Se o post for verdadeiro inicia a função do model
if($this->input->post('inserir'))
{
$data = $this->dicas_model->image_upload();
if($data['status'])
{
echo 'Yei everythings fine';
}
else
{
echo $data['error'];
}
}
}
Model: (yes i make 3 pictures from one hehehe)
Code:
public function image_upload()
{
$config = array(
'allowed_types' => 'gif|jpg|png',
'upload_path' => $this->image_folder,
'max_size' => 4096
);
$this->load->library('upload', $config);
//Se deu tudo certo inserindo a imagem
if ($this->upload->do_upload('imagem'))
{
//Todas informações da imagem
$image_data = $this->upload->data();
$this->load->library('image_lib');
//resize imagem
$config = array(
'image_library' => 'gd2',
'source_image' => $image_data['full_path'], //contém o caminho completo da imagem
'maintain_ratio' => TRUE,
'width' => 1024,
'height' => 768
);
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
//thumb imagem
$config = array(
'image_library' => 'gd2',
'source_image' => $image_data['full_path'],
'new_image' => $image_data['file_path'] ."thumb_". $image_data['file_name'],
'maintain_ratio' => TRUE,
'master_dim' => 'width',
'width' => 256,
'height' => 192
);
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
//crop imagem 128x128
$config = array(
'image_library' => 'gd2',
'source_image' => $image_data['file_path'] ."thumb_". $image_data['file_name'],
'new_image' => $image_data['file_path'] ."crop_". $image_data['file_name'],
'maintain_ratio' => FALSE,
'width' => 128,
'height' => 128,
'x_axis' => 0,
'y_axis' => 0
);
$this->image_lib->initialize($config);
$this->image_lib->crop();
$this->image_lib->clear();
//Insere id, id da dica e nome da imagem principal no ba
$registro = array(
'dica_id' => $this->input->post('dica_id'),
'img' => $image_data['file_name']
);
$data['status'] = $this->db->insert('dicas_imgs', $registro);
return $data;
}
else
{
$data['status'] = false;
$data['error'] = $this->upload->display_errors();
return $data;
}
}
Hope u guys can understand me and have something to make my coding better...
Just need some tips, need to know if i am on the right way to be a good CI developer hehehehe
And by the way sorry bout my english cuz i am from Brasil
Cheeers everyone!