Search code examples
phpcodeignitervalidationmodel-view-controllercontroller

how to display validation errors inside the controller of codeigniter?


I have basic codeigniter mvc structure where my form data comes into controller and checks for the validations. i am writing an API to give back the data or to display the errors. what function should i use to get the validation errors in the controller?


Solution

  • $this->validator->getErrors();
    

    This line will give you errors in the JSON format.

    Example:

    { "mobile_no": "The mobile_no field is required." }