CodeIgniter Controller Method Parameters Issue

Sanganabasu picture Sanganabasu · Mar 21, 2013 · Viewed 13.1k times · Source

I'm using codeigniter 2.1 and I defined a function as follows.

public function reset($email, $hash) {

}

According to MVC architecture and OOPS concept, the function could not execute if I did not pass the parameters in the url. But in codeigniter this function gets executing, So how can i overcome this?. Please help me to find solutions.

Answer

Erman Belegu picture Erman Belegu · Mar 21, 2013

Just you need to define null parametra like this:

public function reset($email = null, $hash = null) {

}

If you call function

(controller name)/reset/[email protected]/dsadasda

than $email = [email protected] & $hash = dsadasda

if you function

(controller name)/reset

than $email and $hash will be null.

Also you can declare default parametre like this.

public function reset($email = [email protected], $hash = dsadasdas) {

}

Hope that I was clear.