UPDATE not work, PLZ Help me |
[eluser]Leftfield[/eluser]
Everybody Hello! I did not clear the problem with the Update method, my simle method UPDATE does not work,and i have some problems with pass $id var into my update method , plz i need help of CI guru, thats my code: Controller Code: function pageedit($id) { Code: function update($data, $id) { View (Form) Code: <form id="form1" name="form1" method="post" action="/admin/pageedit/"> Here is what I get Quote:A PHP Error was encountered What am I doing wrong, tell me please ?
[eluser]Buso[/eluser]
your method is expecting $id to come via GET, and you are sending it via POST try fetching it like this: Code: $id = $this->input->post('id'); and remove $id from function pageedit($id) anyway I can't see the id anywhere in the form another option would be adding it to the form action uri
[eluser]Leftfield[/eluser]
[quote author="Buso" date="1276373230"]your method is expecting $id to come via GET, and you are sending it via POST try fetching it like this: Code: $id = $this->input->post('id'); and remove $id from function pageedit($id) anyway I can't see the id anywhere in the form another option would be adding it to the form action uri[/quote] Plz say how to put it id into form and Quote:another option would be adding it to the form action uriif i remove Quote:and remove $id from function pageedit($id)i loose data in edit form page and i see many Notice like Quote:A PHP Error was encounteredthank you
[eluser]Buso[/eluser]
this would be an example of sending id = 5 via url: Code: <form id="form1" name="form1" method="get" action="/admin/pageedit/5"> but you probably want to make it a variable, so you should write something like: Code: <form id="form1" name="form1" method="get" action="/admin/pageedit/<?php echo $id; ?>"> Another way could be adding a hidden field, with name='id' and value='5' for example, and receive its value via post with the rest of the form data
[eluser]Leftfield[/eluser]
If i replace like you Quote:<form id="form1" name="form1" method="get" action="/admin/pageedit/<?php echo $id; ?>"> then i ricive on my admin/pageedit/54 action Quote:A PHP Error was encountered Quote:And when i push the button Edit i ve got Quote:An Error Was Encountered and URL via Quote:admin/pageedit/<div style= Now my code look like: Controller Code: function pageedit($id) { Model Code: function update($id, $data) { Code: <form id="form1" name="form1" method="post" action="/admin/pageedit/<?php echo $id ?>"> Plz can you show me right way, im gone insane I really want to make it work
[eluser]Buso[/eluser]
you have to pick an option, send the id via GET or POST if you pick get, you have to put the id in the form action, and receive it as a parameter of the function if you pick post, you have to put the id in a hidden field, and receive it using $this->input->post for debugging you can set a default value for id, like this Code: function pageedit($id=NULL) { maybe that way you can see what's going on
[eluser]Matthieu Fauveau[/eluser]
You cannot pass variables to a controller method (except when they are used as internal functions inside the controller). You just need to pass the $id of the db record to your view and post it via the form either via hidden field or via the action parameter. Then fetch it via $this->input->post (or ->get) and call your model function.
[eluser]Buso[/eluser]
Huh? Yes you can, I do it all the time http://ellislab.com/codeigniter/user-gui.../urls.html
[eluser]Matthieu Fauveau[/eluser]
You missunderstood me Buso. In is code he has a controller method Code: function pageedit($id) { when it should be Code: function pageedit() {
[eluser]Buso[/eluser]
It can be the first! And actually it's the easiest way Just write the id in the form action, like action='admin/pageedit/123', and '123' will be received as a parameter of the pageedit function |
Welcome Guest, Not a member yet? Register Sign In |