這個函數有問題。目前,我已經設置了我的網站,因此只有在用戶登錄後才能訪問What's On和Offers頁面。如果他們單擊這些頁面,他們將被重定向到登錄頁面。CakePHP Auth-> login()函數不起作用
不幸的是,當用戶登錄時,登錄頁面只是刷新而不是簽入並將其重定向到索引頁面。
我的用戶表具有以下字段:user_id,名,姓,電子郵件,密碼,創建,修改。
這是我的登錄功能,該功能在UsersController代碼:
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
}
$this->Session->setFlash(__('Invalid username or password, try again'));
}
這是我的AppController的代碼:
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $helpers = array(
'Session',
'Html' => array('className' => 'BoostCake.BoostCakeHtml'),
'Form' => array('className' => 'BoostCake.BoostCakeForm'),
'Paginator' => array('className' => 'BoostCake.BoostCakePaginator'),
);
// CakePHP documentation tutorial
public $components = array(
'Session',
'DebugKit.Toolbar',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'pages',
'action' => 'index'
),
'logoutRedirect' => array(
'controller' => 'pages',
'action' => 'display',
'home'
),
'flash' => array(
'element' => 'alert',
'key' => 'auth',
'params' => array(
'plugin' => 'BoostCake',
'class' => 'alert-error'
)
)
)
);
public function beforeFilter() {
$this->Auth->allow('index', 'contact');
}
}
這是我的代碼爲login.ctp:
<!-- Sign in Form which is on the left hand side of the screen -->
<div class="col-xs-6">
<?php echo $this->Form->create('User', array(
'inputDefaults' => array(
'action' => 'login',
'div' => 'form-group',
'label' => array(
'class' => 'col col-md-3 control-label'
),
'wrapInput' => 'col col-md-9',
'class' => 'form-control'
),
'class' => 'well form-horizontal'
)); ?>
<?php echo $this->Form->input('email', array(
'placeholder' => 'Email'
)); ?>
<?php echo $this->Form->input('password', array(
'placeholder' => 'Password'
)); ?>
<!-- Sign in button for the sign in form -->
<div class="form-group">
<?php echo $this->Form->submit('Sign in', array(
'div' => 'col col-md-9 col-md-offset-3',
'class' => 'btn btn-default'
));
echo $this->Form->end(); ?>
</div>
<div class="row">
<h5 small><?php echo $this->Html->link("Not registed? Click here to register!", '/users/register') ?></h5>
</div>
希望有人能指出出了什麼問題
使用CakePHP 2.4.6,現在將嘗試了這一點! –
這也不起作用,您如何在CakePHP中進行調試? –
簡單地說,像echo $ this-> Auth-> redirect()或print_r($ this-> Auth-> redirect());然後是出口;甚至像回聲「我現在在這裏」;會給你一些見解腳本的見解。 –