Welcome Guest, Not a member yet? Register   Sign In
how to pass empty string as a parameter value
#1

[eluser]searain[/eluser]
In codeigniter smart url, for example

http://www.mysite.com/mail/a/b/c

This pass three parameters to mail function. First parameter is 'a', second parameter is 'b' and third parameter is 'c'.

But what if the first parameter value is ''. How do I pass it?

Thanks!
#2

[eluser]sketchynix[/eluser]
Since you are pulling the variables from the url your function looks something like this, correct?
Code:
function test($a,$b,$c){}

if you want that third parameter to default to '', you can do
Code:
function test($a,$b,$c=''){}

Hope that helps
#3

[eluser]pbreit[/eluser]
I think he wants to know what to do if "a" is "". This is yet another reason why CodeIgniter's lack of querystring support is so dang annoying. It is completely insane to try to do everything with path parts.

The simple answer woud be http://www.mysite.com/mail?a=&b=&c=
#4

[eluser]sketchynix[/eluser]
I see... well though not ideal, you can turn them on in individual controllers...

Code:
class complete extends Controller{

function complete(){
        parent::Controller();
        parse_str($_SERVER['QUERY_STRING'],$_GET);
    }
function search_complete($term=""){

}
}

request url = http://example.com/index.php/complete/se...lete/?term=
#5

[eluser]Jelmer[/eluser]
I've solved it in the past by putting a dash or a zero there and then translate it in the function:
Code:
function mail( $a, $b, $c )
{
    foreach( array( 'a', 'b', 'c' ) as $var )
    {
        if ( $$var == '-' )
            $$var = '';
    }
    // rest of the function
}
So using a marker (in this case '-') to represent an empty string and replacing it in the function with an actual empty string.

URI example: http://www.mysite.com/mail/-/some/thing
Results in:
Code:
$a = '';
$b = 'some';
$c = 'thing';
#6

[eluser]searain[/eluser]
Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB