views:

293

answers:

1

I have a "Posts" and a "Users" controller. I use the Auth Component and I want that all users can visit "Post.index" but only logged in users can visit "User.index".

In my app_controller.php I have this

$this->Auth->allow('signup', 'confirm', 'index');

but with that all users can visit post.index and user.index. How can I specify a Controller in the allow-method?

This didn't work for me:

$this->Auth->allow('signup', 'confirm', 'Post.index');

update I removed 'index' from the app_controller.php and instead set it in the beforeFilter method in the post controller:

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

I also set a variable "loggedIn" in app_controller, without calling "parent::beforeFilter();" I got an "undefined variable" notice.

thx sibidiba

+3  A: 

The period will not work. You could try '/' instead. If that fails as well, you should set $this->Auth->allow('index') in PostController's and UserController's ::beforeFilter() individually. Don't forget to call parent::beforeFilter().

sibidiba
Perfect answer!It didn't work with '/' so I removed 'index' from the app_controller and allowed it in the post controller: function beforeFilter() { parent::beforeFilter(); $this->Auth->allow('index');}
nolandark