Allow entire controller in CakePHP Auth and allow() doesn't work

Karma picture Karma · Jul 3, 2013 · Viewed 8.8k times · Source

I have tried to perform

$this->Auth->allow() in beforeFilter() but, I need to add entire controller as an exception, i.e. it needs to be public and does not require user to be signed in.

Just a short-cut way to perform $this->Auth->allow( every-function-in-this-controller )

Answers?

Edit:

I have this:

<?php

App::uses('AppController','Controller');

class AllzonesController extends AppController {

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

    public function index() {
        $this->layout = 'main';
        $this->set('Hello',"Hello world");
    }
}

It is transferring Auth-login()

Answer

Nunser picture Nunser · Jul 3, 2013

What you proposed is the appropiate way of what you want to do

public function beforeFilter() {
    $this->Auth->allow();
}

Reading the API docs

Takes a list of actions in the current controller for which authentication is not required, or no parameters to allow all actions.

So the function with no parameters should allow a normal user (not logged in) to access every action of that controller.

EDIT :

Sorry, missed the version reference in your tag. In here it says

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

is the appropiate way for Cake 2.0 (and previous versions, as noted by @mark)