Welcome Guest, Not a member yet? Register   Sign In
Need example for record add/edit with image upload
#1

[eluser]Frank Rocco[/eluser]
Hello,

I have a table with:
Item(int),
Item_name(varchar 25),
Price (decimal 9.2),
small_image(varchar 50),
large_image(varchar 50)

I need to add/edit/delete record and allow image upload and save path in the table.

now quite sure how to handle this is the controller.

Thanks

Frank
#2

[eluser]mi6crazyheart[/eluser]
Writing SQL query in controller is not a good place at all. For that try to use MODEL function. You can build separate model function for each job(insert/Update/delete).

For making sql query u can use CI's active record class: http://ellislab.com/codeigniter/user-gui...ecord.html
#3

[eluser]Frank Rocco[/eluser]
Sorry, I am asking on the logic to upload and save the path when the user saves the record.
All DB work will be down in the model.

Controller:
1. validate
2. any errors
3. upload
4. any errors
5. save

Not sure how to code the controller to do this.
#4

[eluser]Bramme[/eluser]
Read this:
http://ellislab.com/codeigniter/user-gui...ading.html
#5

[eluser]Frank Rocco[/eluser]
Code:
if ($this->form_validation->run() == FALSE)
{
   if ( ! $this->upload->do_upload()) saveData();
} else {
display errors
show form
}

Would this be the best approach?
#6

[eluser]mi6crazyheart[/eluser]
@Frank Rocco
You can go by these steps:

[1] upload the image by http://ellislab.com/codeigniter/user-gui...ading.html
[2] Save the image path in variable & pass that to a model function
[3] Now, in the model function save that image path in to a respective table.
#7

[eluser]Frank Rocco[/eluser]
Ok, thank you




Theme © iAndrew 2016 - Forum software by © MyBB