Welcome Guest, Not a member yet? Register   Sign In
Accessing a function directly
#1

[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?
#2

[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
#3

[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.
#4

[eluser]Randy Casburn[/eluser]
You're quite welcome. We all have those days.




Theme © iAndrew 2016 - Forum software by © MyBB