public function action_store_message() { if (!$this->request->post('message') || !is_array($this->request->post('message'))) { return $this->response->status(400); } $validator = Validation::factory($this->request->post('message')); $validator->rule(true, 'not_empty')->rule('username', 'alpha_numeric')->rule('username', 'max_length', [':value', 32])->rule('message_text', 'max_length', [':value', 250])->rule('email', 'email'); if (!$validator->check()) { $errors = []; foreach ($validator->errors('validation') as $errorMessage) { $errors[] = $errorMessage; } return $this->response->headers('Content-Type', 'application/json; charset=utf-8')->body(json_encode(['errors' => $errors])); } $message = new Model_Message(); $message->store($this->request->post('message')); return $this->response->status(200); }