Monday, January 2, 2012

Question about posts index and auth issue

Hi,

I have a page, where I want to display my blog posts by calling a
requestAction to a function called frontindex() function.
public function frontindex() {
$all = $this->Post->find('all', array('order' => 'created
DESC'));
$this->set('posts', $all);
return $all;
}
I am only displaying the headline and the body, nothing else.

To add new posts and to edit I want the admin to login.
After login, the admin should see the index(), with add(), edit() and
delete() function.

I wonder now, how to do this best.

In my posts controller I have this:
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow(array('frontindex'));
}

BUT!

After submitting the login form, I can never reach the index() I just
keep seeing the login form.
In my AppController I have:
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'posts', 'action'
=> 'index'),
'logoutRedirect' => array('controller' => 'pages',
'action' => 'display', 'home'),
'authorize' => array('Controller'),
'authError' => 'Bitte loggen Sie sich ein!'
)
);


It only works, when I do this:
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow(array('index', 'frontindex'));
}
Adding the index.
BUT then my index is open to the public.

I am totally lost in this, how the hell can I make it right?
Please give me some advice!

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: