Wednesday, December 12, 2012

$this->Auth->logout() redirection

Hi,
i have two controllers.
PostsController
<?php
class PostsController extends AppController {
public $helpers = array('Html', 'Form');
public function index() {
$this->set('posts', $this->Post->find('all'));
}
public function view($id = null,$title = null) {
$this->Post->id = $id;
$this->Post->title = $title;
$this->set('post', $this->Post->read());
}
public function add() {
$this->set('tests', $this->Post->find('all', array(
'fields' => 'title',
'conditions' => array('id>0')
  )));
if ($this->request->is('post')) {
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash('Your post has been saved.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to add your post.');
}
}
}
public function edit($id = null) {
$this->Post->id = $id;
if ($this->request->is('get')) {
$this->request->data = $this->Post->read();
}else {
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash('Your post has been updated.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to update your post.');
}
}
}
public function delete($id) {
if ($this->request->is('get')) {
throw new MethodNotAllowedException();
}
if ($this->Post->delete($id)) {
$this->Session->setFlash('The post with id: ' . $id . ' has been deleted.');
$this->redirect(array('action' => 'index'));
}
}
}
UsersController
<?php
class UsersController extends AppController {
public $helpers = array('Html', 'Form');
public $name = "Users";
public function beforeFilter(){
parent::beforeFilter();
$this->Auth->allow('add');
}
public function login() {
if($this->request->is("post")){
if($this->Auth->login()){
$this->redirect($this->Auth->redirect());
}else{
$this->Session->setFlash("Invalid username/password!");
}
}
}
public function logout(){
$this->Auth->redirect($this->Auth->logout());
}
public function add(){
if ($this->request->is('post')) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash('-User has been registered.');
$this->redirect(array('action' => 'login'));
} else {
$this->Session->setFlash('-Unable to add user.');
}
}
}
}
-------------------------------------------------------------
When i tried to logged out it is redirecting to 


 AppController
<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

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

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
 */
class AppController extends Controller {
public $components = array(
"Session",
"Auth"=>array(
"loginRedirect"=>array("controller"=>"Posts","action"=>"index"),
"logoutRedirect"=>array("controller"=>"Posts","action"=>"index"),
"authError"=>"You are not authorized user! Please Login",
"authorize"=>array("Controller")
)
);
public function isAuthorized($user){
return true;
}
public function beforeFilter(){
$this->Auth->allow("index","view");
$this->set('logged_in', $this->Auth->loggedIn());
$this->set('current_user', $this->Auth->user());
}
}
******************************************************************************
I want to redirect http://localhost/blogpost/ after logout.


Thanks

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: