CakePhp is ignoring my model

0

I have an "Admin" plugin and it has the following: UsersController.php (UsersController), User.php (it's the Model User). In this case, I am saving user data, the controller correctly saves the data, however the validation functions, password encryption and any other that I put in the controller, even for testing, do not load. Follow below:

UsersController.php (UsersController) ---

class UsersController extends AdminAppController {

    public $name = 'Users';
    var $helpers = array('Form', 'Html');

    public function index() {
        $name =  $this->set('users', $this->User->find('all'));
    }

    public function add() {
        if ($this->request->is('post')) {
            $this->User->create();

            if(isset($this->data)){
            $this->User->set($this->data); 
                if ($this->User->validates()){
                    if ($this->User->save($this->request->data)) {
                          $this -> Session -> setFlash('Usuario cadastrado!');
                          $this -> Redirect(array('action' => 'index'));
                          exit();
                    } else {
                        $this -> Session -> setFlash('Nao foi possível, cadastrar usuario. Por favir aguarde!');
                        $this -> Redirect(array('action' => 'add'));
                        exit();                
                    }
                }
                else{
                     $this -> Session -> setFlash($this->User->invalidFields());
                     $this -> Redirect(array('action' => 'add'));
                     exit();                
                }
            }
        }
    }
}

User.php (it's the Model User) ---

class User extends AppModel {
    public $name = 'User';

   public $validate = array(
        'username' => array(
            'rule' => 'notEmpty',
            'message' => 'Nome obrigatorio'
        ),
        'password' => array(
            'rule' => 'notEmpty',
            'message' => 'Senha Obrigatoria'
        ),
        'email' => array(
            'rule' => 'notEmpty',
            'message' => 'E-mail obrigatorio'
        ),
        'group_id' => array(
            'rule' => 'notEmpty',
            'message' => 'Grupo obrigatorio'
        )
    );

    public function beforeSave($options = array()) {
        if (isset($this->data['User']['password'])) {
            $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
        }
        return true;
    }
}

Table in the database is users

    
asked by anonymous 08.08.2014 / 21:56

1 answer

0

Is your model within the plugin?

If you try to use the controler:

public $uses = array(
    'Admin.User',
);

If you do not have the plugin use:

public $uses = array(
    'User',
);

Make these calls before the Helper calls on your controller.

    
09.08.2014 / 16:18