【问题标题】:cakephp session can't be writtencakephp 会话无法写入
【发布时间】:2011-05-13 17:21:18
【问题描述】:

控制器

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

<?php print $eyeColor; ?>

【问题讨论】:

  • 您是否收到任何错误消息?您是否正确配置了会话?
  • 你是否在控制器中包含了会话组件?
  • @Juhana:你不必在控制器中包含会话组件,它会自动加载。
  • 啊,很高兴知道。

标签: php session cakephp


【解决方案1】:
<?php echo $session->read('eyeColor') ?>

手册中有:http://book.cakephp.org/view/1466/Methods

诚然,这不是很清楚。也许我会提交更新。

【讨论】:

    猜你喜欢
    • 2015-04-02
    • 2011-05-14
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    • 2016-03-11
    • 2014-09-10
    • 1970-01-01
    • 2014-10-13
    相关资源
    最近更新 更多