Calling one method from another within the same controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Calling one method from another within the same controller (/showthread.php?tid=38546) |
Calling one method from another within the same controller - El Forum - 02-10-2011 [eluser]Unknown[/eluser] I'm trying to add error messages and prompts at the top of pages, rather than redirecting to new pages. For instance, when I link to 'user/delete', I tell my controller to load an alert variable, and then run the usual 'user/view' method: Code: function delete() (I'm "paraphrasing" my code here, there's more to it than that.) Note that I have use 'return' to keep CI from continuing through the delete function. This works, but it really doesn't feel like the best way of doing this. I was using $this->session->set_flashdata() for the alert and then redirecting to 'user/view', but that seems even worse since it requires a redirect that slows things down (right?). Thanks for any advice. Calling one method from another within the same controller - El Forum - 02-11-2011 [eluser]Pedro Luz[/eluser] Hi, Im currently working on a project, and since i dont like the flashdata.. because.. it usualy doesnt work the way i wanted, and i needed to pass messages to the user.. (success, fail, etc), what i did has... in all the methods in the controller i have something like this... i add a $params = array() Code: class User extends CI_Controller then what i have in a little view that loads on top of the page is something like this Code: $count = 0; and with this you generate a table with multiple rows.. each with a message if you want to pass a message to that method, i do somehting like Code: array_push($msgBag["msg"], array("text" => "Added width success", "type" => "success")); where im passing 2 messages to the edit method is not the most accurate way, or the most guru way... but it works for me. |