0

He guys!

I am creating the next controller

function add($action,$data){

}

Wich gives me functionality for the next url:

controller/add/proyect/0

but this is a multiple purpose controller.

So, i need to call it like this:

controller/add/proyect

I dont want to send data, i just want to add the proyect.

when i do that, the compiler sends me the error:

Missing argument 1 for add()

This is what i tried:

function add($action,$data=null){

}

and

function add($action,$data=false){

}

But still not working.

Any ideas?

  • "*It is not working*" is not useful. Please explain, if you get an error message (if so, which one) or if the results differ from your expectation (if so, how). – Amal Murali Mar 12 '14 at 19:24
  • PHP functions allow for optional parameters, by saying `$data=null` you are by default setting $data to null, Also explain what you mean by multipurpose function – Hurricane Development Mar 12 '14 at 19:24
  • **DEFINITE** duplicate of [using a PHP function but missing out the parameters](http://stackoverflow.com/questions/22015895/using-a-php-function-but-missing-out-the-parameters) – MonkeyZeus Mar 12 '14 at 19:24
  • I use `$data=false` all the time -- how isn't that working? – Sterling Archer Mar 12 '14 at 19:25
  • @AmalMurali I already wrote the error message. Please read the entire text. – user3368975 Mar 12 '14 at 19:25
  • @MonkeyZeus why did you link to another duplicate? lol – Sterling Archer Mar 12 '14 at 19:25
  • @user3368975: I've read the entire answer. But at the end of the answer, you're just saying "*But still not working.*" without actually saying what error message you're getting or what doesn't work. – Amal Murali Mar 12 '14 at 19:26
  • @RUJordan Facepalm, the correct answer is `function add($action=null,$data=null){` <-- cannot leave just `$action` without giving it a default. – MonkeyZeus Mar 12 '14 at 19:27

1 Answers1

0

The two examples where you set a default for data should be working fine. You don't need to set a default for all parameters.

Your issue probably lies within the function itself. You might have the function set up to only return a value if $data is equal to something. Do you have any lines in the function that say

if(!$data){

or maybe

if(empty($data)){

We definitely need to see the whole function before we can give you an answer why it's not working.

nickbwatson
  • 153
  • 7