cakephp会话可以';不能写
控制器cakephp会话可以';不能写,php,session,cakephp,Php,Session,Cakephp,控制器 function login() { // Don't show the error message if no data has been submitted. $this->set('error', false); // Does not render the view $this->autoRender = false; // If a user has submitted form data: if(!empty($this->
function login() {
// Don't show the error message if no data has been submitted.
$this->set('error', false);
// Does not render the view
$this->autoRender = false;
// If a user has submitted form data:
if(!empty($this->data)) {
$someone = $this->Student->findByStudentEmail($this->data['Student']['email']);
if(!empty($someone['Student']['student_pwd']) && $someone['Student']['student_pwd'] == $this->data['Student']['password']) {
$this->Session->write('eyeColor', 'Green');
$this->Session->write('Student', $someone['Student']);
// session information to remember this user as 'logged-in'.
echo "success";
} else {
echo "failed";
}
}
function main(){
$this->set('students', $this->Student->find('all'));
$this->set('eyeColor', $this->Session->read('eyeColor'));
// Render the specified view
$this->render('/pages/main');
}
查看
main.ctp
手册上有:
不过,不可否认,这并不十分清楚。也许我会提交更新。您是否收到任何错误消息?会话配置是否正确?会话组件是否包含在控制器中?@Juhana:您不必将会话组件包含在控制器中,它是自动加载的。啊,很高兴知道。
<?php print $eyeColor; ?>
<?php echo $session->read('eyeColor') ?>