public function __construct() { // load database library into $this->db (can be omitted if not required) parent::__construct(); }
public function removeSetting() { $user = $this->authenticate(); $emptyrequest = !isset($_GET) && !isset($_POST) || sizeof($_GET) == 0 && sizeof($_POST) == 0; $input; if (!$emptyrequest) { $input = new Validation(array_merge($_GET, $_POST)); $input->add_rules('setting_id', 'required', 'numeric'); $validator = new SettingValidation_Model(); $validator->expectedUser_id = $user->user_id; $input->add_callbacks('setting_id', array($validator, "validateExists")); $input->add_callbacks('setting_id', array($validator, "validateUserOwnsSetting")); } else { $input = new Validation(array()); $input->add_error('setting_id', 'required'); } if ($input->validate()) { $setting = new Setting_Model(); $setting->setting_id = $input->setting_id; $setting->retrieveInfoFromDB(); $setting->removeFromDB(); Kohana::render($this->encode($setting)); } else { //@TODO : make better error messages...... Kohana::render($this->encode(NULL, $input->errors())); } }