• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple views from one controller

#1
[eluser]satterle[/eluser]
I think I figured it out on my own!

1. the view statement should be view('delete'), not view('co/delete')
2. going to a different mvc, in this case 'cancel', requires redirect('co/cancel')

------------------------

I have a controller that deletes a record from a database. I set it up as follows:

if($this->input->post('delete'))
{
$this->model->delete($id)
$this->load->view('co/delete', $data)
}
else if($this->input->post('cancel'))
{
$this->load->view('co/cancel', $data)
}
else
{
$this->load->view('co/delete', $data)
}

When I load the page the first time (the else condition), no problem.
When I try to load the page from the if conditions, I get an error message "unable to load the requested file: name of file".

I know that the if statements are working because a) a record is deleted when I click the delete button and b) the error message displays the appropriate file name when I click on the different buttons on the form.

Why don't the views load? How do I correct?

#2
[eluser]nanda[/eluser]
I'm not sure why its not working, I would double check that the files are where you specified and that they are named exactly right (no typos). Otherwise, sorry :-S

#3
[eluser]Scriptor[/eluser]
I'm guessing cancel was a controller method, and not a view Smile
If that's the case, remember the difference between a view and a controller method. Loading a view will simply look in the views folder for the file you specified. If you need to go to another method in a controller, you have to use redirect, which use a HTTP redirect, which basically tells the browser to load a completely new URL.
Hope that helps, remember to always find out both what works, and why it works.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.