Welcome Guest, Not a member yet? Register   Sign In
Sending and recieving an extra parameter through url only if it exists
#1

[eluser]jonny68[/eluser]
Hi,

i'm building an e-shop and i'm facing a little problem:

i have in the view:
(this is a link)
Code:
site_url('cart/remove_item/'.$cartkey);

pointing at cart controller function remove_item
Code:
function remove_item($key)
{
  //here i do things only with $key..
}

My need is that the link takes another parameter to take to the function
but only if it is set, and the function takes that parameter only if it is set as well.
I try to explain, something like:
Code:
site_url('cart/remove_item/'.$cartkey,(isset($myvar)) && $myvar));
Code:
function remove_item($key,(isset($myvar)) && $myvar))
{
  //here i do things with $key and $myvar too..
}

I'm i clear enough?

Hope so an thanks in advance!



#2

[eluser]craig.hoog[/eluser]
I believe what you want to do is adjust your function first.

Code:
function remove_item($key, $myvar = null)
{
    if(isset($myvar) && $myvar)
    {
         // I have $myvar
    }
    else
    {
         // I do not have $myvar
    }
}

Once you have that, the function will just determine whether or not you sent the second variable.
I don't think you can / need to do anything in the site_url(), but I may have misunderstood your needs.
#3

[eluser]Aken[/eluser]
There's a big difference between whether a variable is set and whether it has a value. Keep that in mind when doing your checking. An isset() check in your remove_item() method is not the way to go.




Theme © iAndrew 2016 - Forum software by © MyBB