我正在運行CakePHP 1.3.8 stable並且我遇到了表單數據的問題。當我提交表單時,我可以在AppController中調試時看到$this->data
中包含的數據,但在操作所在的子控制器中爲空。
這裏是我的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();
}
}
這是我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['User']['role_id'] = $defaultRole['id'];
if($this->User->save($this->data)) {
$this->redirect(array('action' => 'index'));
}
}
}
}
}
的形式張貼到/用戶/註冊
謝謝!