2013-12-19 04:23
浏览 35


Since vanilla CakePHP doesn't handle password fields very well on user edit views (echoing the hashed password into the password field, etc), I'm trying to use dereuromark's PasswordableBehavior to handle user registration and password updates.

I tried following the tutorial ( making the following changes, but the server keeps throwing an error. What is the problem here? Because the error is in PasswordableBehavior.php, I'm not 100% certain I'm screwing up.


public function register() {
if ($this->request->is('post') || $this->request->is('put')) {
    if ($this->User->save($this->request->data, true, array('username', 'name', 'email', 'pwd', 'pwd_repeat', 'group_id'))) {
    $this->Session->setFlash(__('The user has been saved'), 'flash/success');
            $this->redirect(array('action' => 'index'));
} else {
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'), 'flash/error');

and register.ctp (possible security hole alert)

echo $this->Form->create('User', array('role' => 'form'));
echo $this->Form->input('username', array('class' => 'form-control'));
echo $this->Form->input('name', array('class' => 'form-control'));
echo $this->Form->input('email', array('class' => 'form-control'));
echo $this->Form->input('password', array('class' => 'form-control'));
echo $this->Form->hidden('group_id', array('value'=>3));
echo $this->Form->submit('Submit', array('class' => 'btn btn-large btn-primary'));
echo $this->Form->end();

Finally, the server error:

Strict (2048): Declaration of PasswordableBehavior::beforeValidate() should be compatible with ModelBehavior::beforeValidate(Model $model, $options = Array) [APP/Plugin/Tools/Model/Behavior/PasswordableBehavior.php, line 338]
Strict (2048): Declaration of PasswordableBehavior::beforeSave() should be compatible with ModelBehavior::beforeSave(Model $model, $options = Array) [APP/Plugin/Tools/Model/Behavior/PasswordableBehavior.php, line 338]
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongxia9519 2013-12-19 05:30

    1) Strict errors are not a big deal. IMO just turn off Strict Error Reporting.

    2) The errors you're seeing are because the two methods in the Behavior (beforeValidate() and beforeSave()) don't have the full options.

    Just make sure they have the correct options like below, and the strict errors will go away:

    public function beforeValidate(Model $model, $options = array()) {
    public function beforeSave(Model $model, $options = array()) {
    打赏 评论

相关推荐 更多相似问题