PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 22, 2022

[FIXED] How to allow actions in CakePHP?

 April 22, 2022     authentication, cakephp, cakephp-2.3     No comments   

Issue

I make something horribly wrong in Cake 2.3.6 stable. I followed the Auth tutorial and added in the AppController:

public function beforeFilter() {
    $this->Auth->allow('index', 'view');
}

But when I enter the site on the homepage, cake throws that I´m not authorized to access that location.

With no effect I tried in the PagesController:

public function beforeFilter() {
    parent::beforeFilter();
    $this->Auth->allow('index');
}

I double checked the tutorial and my code, there are no differences except I had to swap "$this->Post" with "$this->Calclulation" in CalculationsController. Furthermore the login- and logout-redirects in AppController doesn´t work.

public $components = array(
    'Session',
    'Auth' => array(
        'loginRedirect' => array('controller' => 'calculations', 'action' => 'index'),
        'logoutRedirect' => array('controller' => 'pages', 'action' => ''),
        'authorize' => array('Controller')
    )
);

How could it be solved? Thanks in advance :)


Solution

Please, check default routers. app/Config/routes.php

Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

this mean, that home page is actulay rendered by pages controller and action display, so, you should allow display

$this->Auth->allow('display');


Answered By - Vadim
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing