Generally you can make specific actions public using the auth components allow()
method.
Making pages public may require a little more work in case you'd want to make only specific pages public, since the PagesController
handles all pages in a single action (display()
). If that is the case, then you could utilize request->params['pass'][0]
which will hold the page name, test this against a list of allowed pages, and then allow the display
action using Auth::allow
.
Example, in the PagesController
:
public function beforeFilter()
{
parent::beforeFilter();
$allowedPages = array('home', 'foo', 'bar');
if(isset($this->request->params['pass'][0]) &&
in_array($this->request->params['pass'][0], $allowedPages))
{
$this->Auth->allow('display');
}
}
This would allow the pages home
, foo
and bar
to be viewed without being logged in.
If you'd wanted to make all pages public, then you could simply use Auth::allow
without any conditions, ie:
public function beforeFilter()
{
parent::beforeFilter();
$this->Auth->allow('display');
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…