これは私の問題です: 私は管理領域を持っており、 name と password でログインすることによってそれを保護しています。
URL を入力すると、localhost/admin/area のようなものを意味し、localhost/user/admin にリダイレクトされます
問題は、localhost/admin/545 のような間違ったアドレスを入力する
と、管理者エリアに移動し、Controller でエラーが発生することです
これは私のコードです:
AppController:
function beforeFilter()
{
$this->Auth->loginAction = array('controller'=>'users','action'=>'login','admin'=>false);
$this->Auth->authorize = array('Controller');
if(!isset($this->request->params['prefix']))
{
$this->Auth->allow();
}
if(isset($this->request->params['prefix']) && $this->request->params['prefix'] == 'admin')
{
$this->layout = 'admin';
}
}
function isAuthorized($user)
{
if(!isset($this->request->params['prefix']))
{
return true;
}
}
メニュー:
<?php
$pages = $this->requestAction(array('controller'=>'pages','action'=>'menu','admin'=>false)); ?>
<a href="/index"><img class="title" src="/img/title.png" alt="studio"></a>
<ul class="menu">
<?php foreach($pages as $k => $v): $v = current($v);?>
残りのコードは次のとおりです。
ログイン機能:
function login()
{
if ($this->request->is('post'))
{
if ($this->Auth->login())
{
return $this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash("Votre login ou votre mot de passe ne correspond pas");
}
}
}