Welcome Guest, Not a member yet? Register   Sign In
Best practice of loading views in editing record
#1

[eluser]Awais Qarni[/eluser]
Hello I am new to codeigniter. I am learning this framework by developing a testing application. I am showing user listing and in front of each record an anchor tag to edit that record.
That anchor tag looks like
Code:
echo(anchor('first/edit_user/'.$value->id,'Edit'));
It redirects the browser to first controller and edit_user function. At edit_user function I load the view of edit like this.
Code:
$this->load->view('edit_user',$data);
. It loads the view with respect to selected record to edit the record and the url looks like
Code:
http://localhost/CodeIgniter/index.php/first/edit_user/9
. Every thing works fine. But when user clicks the update button it again comes to same function. It updates record and then again tries to load the same view but here a problem occurs. Now after updating record it loads the view and url becomes like this
Code:
http://localhost/CodeIgniter/index.php/first/edit_user
. It creates error as it is not having the id of the selected record. IF i change the load view code of my function like this
Code:
$this->load->view('edit_user/'$this->uri->segment(3)),$data);
. It generates an error of edit_user/.php is not defined and some thing like that.
Now I want to ask How can I Redirect the user to same edit form telling that his record has been updated? How to load the view of selected record from function of the controller?
#2

[eluser]davidbehler[/eluser]
What does your code for the form look like, especially the <form> tag?
I suspect that's where your problem is.
#3

[eluser]Awais Qarni[/eluser]
My from tag look like
Code:
<?php echo(form_open('first/edit_user'));?>
#4

[eluser]osci[/eluser]
you should pass your id to the view and in your form

Code:
<?php echo(form_open('first/edit_user/'.$id));?>
#5

[eluser]Awais Qarni[/eluser]
Hi Thanks for your reply. I have got the solution by your answer. Thanks you dude




Theme © iAndrew 2016 - Forum software by © MyBB