views:

179

answers:

1

Hello,

I am using CodeIgniter and in my controller I have

function index($var_22) {
 // BLABLA
}

So if I dont pass the $var_22 variable I will get an error:

A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for Claims::index()

But I dont need to pass it all of the time, what should I use when I do not pass that variable in order not to get the error. (I dont want to turn off global error reporting)

Thanx

+3  A: 

You can set a default value for it and then check into the controller code if the parameter is default or not. Something like this:

function index($var_22 = FALSE)
{
   if (!$var_22) {
       // code for the initialized parameter
   } else {
      // code with no parameter
   }    
}

or

function index($var_22 = "")
    {
       if (!empty($var_22)) {
           // code for the initialized parameter
       } else {
          // code with no parameter
       }    
    }
mg