lundi 25 avril 2016

Proper handling of errors stored in a class in code igniter

I am doing a project using code igniter and I have to pass all error messages to ajax. So I'm thinking of putting them in an array. How can I go about this?

The first approach I've thought is to create a class that store all error messages and displays them, like this.

class errors {
    public $errorList = array();
    public function set_error($key, $message)
        $errorList[$key] = $message;
    }

    public function display_errors()
    {
        return $errorLis;
    }
}

I would use it like this:

public function upload_file()
{
    // if file not uploaded,
    set_error("file upload", $this->upload->display_errors());
}

Is this approach fine? What is wrong with it? What's a better way?

Aucun commentaire:

Enregistrer un commentaire