У меня есть статическая страница, которую я хочу добавить в существующий проект cakePHP. Мне удалось обойти Auth с помощью этого кода на PagesController
public $allowedPages = array('main',);
public function beforeFilter() {
$this->Auth->allow('display');
}
public function display()
{
$path = func_get_args();
$count = count($path);
if (!$count) {
return $this->redirect('/');
}
$page = $subpage = null;
if (!empty($path[0])) {
$page = $path[0];
}
if (!empty($path[1])) {
$subpage = $path[1];
}
$this->set(compact('page', 'subpage'));
/*add CHU
if(in_array($page, $this->allowedPages) || $this->User->loggedin) {
$this->render($page);
} */
if(in_array($page, $this->allowedPages) ) {
$this->render($page); //here redirects to login page change the path if the path is different
}
try {
$this->render(implode('/', $path));
} catch (MissingTemplateException $e) {
if (Configure::read('debug')) {
throw $e;
}
throw new NotFoundException();
}
}
И добавил маршрут следующим образом:
$routes->connect('/main', ['controller' => 'Pages', 'action' => 'display', 'main']);
Но происходит то, что когда пользователь входит в систему, снова отображается страница входа. Я думаю, что следует добавить проверку, чтобы проверить, вошел ли пользователь здесь:
if(in_array($page, $this->allowedPages) ) {
$this->render($page); //here redirects to login page change the path if the path is different
}
Как я могу это сделать?
Я попробовал эти ответы: Аутентификация для статической страницы
Strict (2048): Declaration of App\Controller\PagesController::beforeFilter() should be compatible with App\Controller\AppController::beforeFilter(Cake\Event\Event $event) [APP/Controller/PagesController.php, line 29] Warning (4096): Argument 1 passed to App\Controller\AppController::beforeFilter() must be an instance of Cake\Event\Event, none given, called in /var/www/sty_reps/src/Controller/PagesController.php on line 34 and defined [APP/Controller/AppController.
- person Yohan Blake   schedule 12.03.2016