Welcome Guest, Not a member yet? Register   Sign In
Missing argument for function
#1

[eluser]ahmedi[/eluser]
Hello,
In one of my controllers , i have function like this price($a,$b),
but in same cases i use url like this /price/value
and i want not to see errors like this :
A PHP Error was encountered

Severity: Warning

Message: Missing argument 2 for Website::price()

If you have an idea ??
#2

[eluser]n0xie[/eluser]
Code:
function price($a,$b = NULL)
#3

[eluser]ahmedi[/eluser]
thanks you man, what is the meaning of puting $b=null ? how it works ?
#4

[eluser]jedd[/eluser]
[quote author="ahmedi" date="1257972488"]thanks you man, what is the meaning of puting $b=null ? how it works ?[/quote]

If you want to know how it works, read the CI source.

If you want to know what it does, it assigns a default value to the $b variable - which will be used if one does not come in via the URL.

It could take you several minutes of experimentation before you worked this out for yourself.

An alternative answer to your first question is to test for the presence of a variable before trying to use it. The isset() function would be appropriate.




Theme © iAndrew 2016 - Forum software by © MyBB