나는이 메시지를 로그인 할 때 내가 로그인 한 사용자를 로그 아웃이 컨트롤러를 사용하고 난 환영 메시지와 문제가 로그 아웃 링크 로그인 사용자 이름을 표시 할 날인쇄 사용자 이름 로그인
에 apear 때 고지 (8) : 정의되지 않은 변수 : 결과 [APP \ 뷰 \ 사용자 \ login.ctp 라인 4
users_controller.php
<?php
# /controllers/users_controller.php
# please note that not all code is shown...
uses('sanitize');
class UsersController extends AppController {
var $name = 'Users';
// Include the Email Component so we can send some out :)
var $components = array('Email','Auth','Recaptcha');
var $helpers = array('Recaptcha');
// Allow users to access the following action when not logged in
function beforeFilter() {
$this->Auth->allow('register','activate','logout','login');
$this->Auth->autoRedirect = false;
}
function login() {
// Check for incoming login request.
if ($this->data) {
// Use the AuthComponent's login action
if ($this->Auth->login($this->data)) {
// Retrieve user data
$results = $this->User->find(array('User.username' => $this->data['User']['username']), array('User.active'), null, false);
// Check to see if the User's account isn't active
if ($results['User']['active'] == 0) {
// Uh Oh!
$this->Session->setFlash('Your account has not been activated yet!');
$this->Auth->logout();
$this->data['User']['password'] = null;
//if not active user
}else {
$this->set('users', $results);
$this->redirect(array('controller' => 'users', 'action' => 'login'));
}
}
}
}
function logout() {
$this->redirect($this->Auth->logout());
}
$this->set('results', $results);
:
사용자/login.ctp
<?php if ($this->Session->read('Auth.User')):?>
<?php
echo "Welcome".'<br />' ;
echo $results;
echo $html->link('logout', array('action'=>'logout'));
?>
<?php else : ?>
<div class="types form">
<?php echo $form->create('User');?>
<fieldset>
<legend><?php echo ('Please enter your username and password'); ?></legend>
<?php
echo $form->input('username');
echo $form->input('password');
?>
</fieldset>
<?php echo $form->end(('Login'));?>
</div>
<?php endif; ?>
대답은 $ 세션을 사용하는 것입니다 참조 -> read ('Auth.User.username') : 로그인 사용자 이름을 인쇄합니다. no print $ results; – serr