![]() |
Bug or Error using validations - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Bug or Error using validations (/showthread.php?tid=75335) |
Bug or Error using validations - Scorpio - 01-27-2020 Hello guys, this is my first post on this community (I'm a newbie on CI, but I love this.). I write this because I have spent many hours looking for a solution for my problem, so I hope that the information is useful to someone or is worth to improve this great framework... Okay, the problem is this, I recently write a model for manage a table on my database, on this table I need to save a lot of IP's addresses. On the counterpart, I coded a function which gives me an array with lots of IP addresses, like a Scraper. The problem appears when I try to save the IP's addresses to the database using the model. This is an example of my model: PHP Code: class IPListModel extends Model And this is what I do for save the IP's: PHP Code: $ipList = array( If anyone run this code will see the following output: Quote:IP 1.1.1.1 Saved on the DataBase As we can see, thanks to the 'is_unique' validation the third address was not added, since it was the first to be saved. This is nice, but what about the fourth address? Don't exists on the Database, but still show the 'is_unique' error. I look on the CI code and on the file ./system/Validation/Validation.php I found this: PHP Code: /** Now we know that the function for doing the validations checks the function 'getErrors' (On the return) for check if any validation error was trigered... So, in this case I assumed that the problem is about this class and the persistence of the previous errors on the new database queries, since I searched on google and on the official documentation but I don't found anything relevant. In this way my solution has been the following, on the file ./system/Model.php (The base model), in the 'save' function, I called the function 'reset' of the 'validation' library before all (Than among other things resets the 'errors' array), giving the following as result: PHP Code: public function save($data): bool This prevents past queries errors from affecting the current query (And now the code works perfect!). But now my question is the next: Is this some quality or characteristic of CI that can be deactivated and I am so noob that I don't know her? Or is really a bug? P.S: Sorry for my bad english. EDIT: Sorry, I forgot to say that I'm using the version 4.0.0 rc3, thanks. //Regards. |