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.

3
  • how you are calling to reset method , I mean can you please provide the url? Commented Mar 21, 2013 at 5:58
  • CI controller function is php function also so it behave same as php function . so function is called as default behavioral of php functoin Commented Mar 21, 2013 at 6:47
  • you should reveal some of your URL and explain how it's getting executed. Commented Mar 21, 2013 at 6:50

2 Answers 2

15

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.

Sign up to request clarification or add additional context in comments.

Comments

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
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.