登錄網站後出現問題。有兩種類型的用戶,即'管理員','僱主'。當我通過僱主登錄後,我可以訪問管理員的禁區。下面是該網站的AppController ..在cakePHP中限制和重定向其他用戶從管理員
class AppController extends Controller {
public $helpers = array('Form', 'Html', 'Js', 'Time', 'Auth');
// Change template extension to .php instead of .ctp
var $ext = '.php';
public $components = array(
'Session',
'Auth' => array(
'loginAction' => array(
'controller' => 'users',
'action' => 'login'
),
'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'authenticate' => array('Form' => array('fields' => array('username' => 'email'))),
'authorize' => array('Controller')
)
);
public function isAuthorized($user) {
// Admin can access every action
if (isset($user['type']) && $user['type'] === 'admin') {
return true;
}
// Default deny
return false;
}
public function beforeFilter() {
$this->Auth->allow(array('view', 'index','assessment','question'));
}
}
現在這裏是控制器有管理方法。
class TopicsController extends AppController {
public $scaffold = 'admin';
public function beforeFilter() {
if($this->Auth->user('type')!='employer'){
parent::beforeFilter();
$this->Auth->allow(array('view', 'index','moveup'));
} else {
$this->Auth->deny(array('view', 'index','moveup'));
$this->redirect(array('controller' => 'employer' , 'action' => 'index'));
}
}
public function isAuthorized($user) {
return true;
}
public function index() {
$this->set('topics', $this->Topic->children());
}
}
如果管理URL是www.example.com/admin/topics,僱主將被重定向到www.example.com/admin/employer這不是重定向正確的網址。
也想知道關於public $scaffold = 'admin';
因爲這對我來說不太清楚。 請幫助我..
有關'$支架=「admin'';閱讀:http://book.cakephp.org/2.0/en/controllers/scaffolding.html。你試過了:'$ this-> redirect(array('controller'=>'employer','action'=>'index','admin'=> false));' –
謝謝Alex,我已經過了鏈接。我從來沒有嘗試過,並希望它的工作很好..非常感謝.. –