开发者

CakePHP $this->data empty in ChildController, not empty in AppController

I am running CakePHP 1.3.8 stable and I have a problem with form data. When I submit my form I am able to see the data contained in $this->data when I debug in the AppController, but it is empty in my child controller where the action is.

Here is my AppController:

class AppController extends Controller {
        var $components = array('Auth', 'Session');

        function beforeFilter() {
                // Data is not empty here
                $this->Auth->authenticate = ClassRegistry::init('User');
                $this->Auth->allow('register', 'index');
                parent::beforeFilter();
        }
}

Here is my UsersController:

class UsersController extends AppController {

        var $name = 'Users';
        function register() {
                // Data empty at this point
                if(!empty($this->data)) {
                        if($this->data['User']['password'] == $this->Auth->password($this->data['User']['password_confirm'])) {
                                $this->User->create();
                                $defaultRole = $this->User->Role->getDefaultRole();
                                $this->data['开发者_Python百科User']['role_id'] = $defaultRole['id'];
                                if($this->User->save($this->data)) {
                                        $this->redirect(array('action' => 'index'));
                                }
                        }
                }
        }
}

The form is posting to /users/register

Thanks in advance!


I figured out what the problem was. I am using a custom hashing method in my Users model and within the hashPasswords function I was not returning the $data object. Thus, $data just got swallowed up by the hashPasswords function never to be seen again.

Thanks for looking and I hope this helps you if you have made a similar mistake!


Also look for unterminated form tags in the views or elements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜