![]() |
Accessing a function directly - 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: Accessing a function directly (/showthread.php?tid=12547) |
Accessing a function directly - El Forum - 10-22-2008 [eluser]CodeIgniterNoob[/eluser] I have a function that passes an id to a destination page that pulls data from a table based on that id. Everything works fine when the URL contains a number at the end like post/1, but when I hit the function directly like post/ it gives errors saying "Message: Missing argument 1 for welcome::post()" . Is there a way to make that URL redirect to another page? Accessing a function directly - El Forum - 10-22-2008 [eluser]Randy Casburn[/eluser] Such a well written question...such a little thought put the problem... Open your most basic PHP reference and find the section on User Defined functions. It will explain that when you demand that PHP expect a parameter as input...it will do exactly what you tell it too. Simply change your method declaration from Code: function post($id) to... Code: function post( $id=NULL ) you can either capture $id=NULL and redirect on that or change $id do a different default value and show a predefined default post. Randy Accessing a function directly - El Forum - 10-22-2008 [eluser]CodeIgniterNoob[/eluser] wow, I guess it required a very simple solution. I was just working all day and didnt see it... Thanks for helping me. Accessing a function directly - El Forum - 10-22-2008 [eluser]Randy Casburn[/eluser] You're quite welcome. We all have those days. |