I try to find a good and clean way to deal with an admin panel "edit user" in cakePHP v.2.7.
To be clear : I want to be able to edit my user with or without overwriting their password, but the cakePHP validator tool don't let me do what I want...
I've already take a look at CakePHP: Edit Users without changing password and Updating user email and password with CakePHP but it seem really dirty :
- the first one don't apply the rules onUpdate
- the second display the hash (just no... u_u")
There is no other way to do it ? (with as few line as possible)
TL;DR :
View
Controller
Ok, I finally get what I want, here is my code :
On your
app/View/Users/edit.ctp
you add a field to your form (a custom one, don't add it to your DB)Don't change your
app/Model/User.php
; here is mine :And on your
app/Controller/UsersController.php
you use this :With the 4 important lines, you are now able to set a new password if needed or disable the validation on the password.
I used this for reference http://book.cakephp.org/2.0/en/models/data-validation.html#removing-rules-from-the-set