6

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.

Sanganabasu
  • 943
  • 7
  • 21
  • 39

2 Answers2

15

Just you need to define null parametra like this:

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

}

If you call function

(controller name)/reset/mail@mail.com/dsadasda

than $email = mail@mail.com & $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 = mail@mail.com, $hash = dsadasdas) {

}

Hope that I was clear.

Erman Belegu
  • 4,074
  • 25
  • 39
1

If you want to execute function with or without parameters you can set default values for it.

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

}

This way when there are no parameters function can still execute. You can use condition for code

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

    if(!empty($email) AND !empty($hash)){
        //your code here
    }
}
Muhammad Raheel
  • 19,823
  • 7
  • 67
  • 103