Wing Hing Raymond Chiu
Wing Hing Raymond Chiu

Reputation: 217

codeigniter's link does not work and cannot match with the function parameter

I have the function

index($errorMsg, $successMsg) {....}

It works when I type in the URL.

http://localhost/website/index.php/home/index/1234/5678

But It does not work But when I type in the URL.

http://localhost/website/index.php/home/index//5678

5678 will be $errorMsg.

Is there any hints

Upvotes: 0

Views: 63

Answers (2)

Shaiful Islam
Shaiful Islam

Reputation: 7134

Your solution

Declare function like this

index($errorMsg, $successMsg=NULL) {....}

Explanation

index($errorMsg, $successMsg) function required both arguments(variables). If you don't pass it will produce error which is happening in your case.

index($errorMsg, $successMsg=NULL) function required first one and 2nd one is optional.If you don't pass 2nd argument $successMsg value will be null.

Note

/home/index//5678 no need use double slash after index.One will solve your purpose.You need to just check $successMsg.If it is null means you passed only $errorMsg

Upvotes: 0

drozdo
drozdo

Reputation: 515

Really bad solution for passing success or error parameters via function arguments by get method in CI.

Try use session flash data to pass success or error messages in redirection view.

$this->session->set_flashdata('errorMsg', '1234');
$this->session->set_flashdata('successMsg', '5678');

And show variables:

function index() 
{
   echo $this->session->flashdata('errorMsg');
   echo $this->session->flashdata('successMsg');
}

Use this solution to avoid errors.

Upvotes: 1

Related Questions