2010-11-22 20 views
0

コントローラ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->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; ?> 
それはマニュアルにあります
+1

エラーメッセージが表示されますか?セッションを正しく設定しましたか? –

+0

セッションコンポーネントをコントローラに含めましたか? – JJJ

+0

@Juhana:コントローラにセッションコンポーネントを含める必要はなく、自動的にロードされます。 – dhofstet

答えて

0
<?php echo $session->read('eyeColor') ?> 

http://book.cakephp.org/view/1466/Methods

を認めます控えめではあるが、それはあまり明確ではない。多分私は更新を提出するでしょう。

関連する問題