Authentication plugin has been installed. If i browse actions of other controllers it redirects to /users/login. How can I allow actions of other controllers?
You want to allow certain actions for people who aren’t logged in? Or you are logged in but still getting redirected to the login page?
In PostsController i have added
public function initialize(): void
{
parent::initialize();
$this->Auth->allow(['index']);
}
I get error:
Call to a member function allow() on null
How can I solve this?
Looks like you are mixing up the new plugin and the old component. See the documentation on the component for the plugin.
I agree with Zuluru: according to the code you typed, you are using the Auth component, and if you use the component, the correct code is normaly (at least in Cake 1.3):
$this->Auth->allow (‘index’);
But in order to be able to use this implementation, you need first to declare the component in the controller your are coding with the line:
var $components = array (‘Auth’);
The message returned by the server means that it doesn’t know anything yet about ‘Auth’. That is why it says “call to a member function ‘allow()’ on null”: $this->Auth returns null considering the actual implementation of the controller you are working on.
The correct code for using the new plugin’s component is different from what is required to use the old component.