I am currently working in cakephp and is facing problem in redirecting a page. By default after login user is taken to a particular page. Now i want to change it a little but dont want to disturb the default functionality. If a user is not logged in the user is redirected to the login page by the following function :
$this->Auth->loginAction = array(
'controller' => 'users',
'action' => 'login'
);
I have defined a link which redirects to login page if user is not logged in when clicked
<div class="bid-button"><a href="/users/login" class="b-login-big"></a></div>
or else this is done when clicked
<?php if($session->check('Auth.User')):?>
<div class="bid-loading" style="display: none; height:59px;"><?php echo $html->image('ajax-arrows-white.gif');?></div>
<div class="bid-button"><a class="bid-button-link button-big" title="<?php echo $auction['Auction']['id'];?>" href="/bid.php?id=<?php echo $auction['Auction']['id'];?>">Bid!</a></div>
<?php endif;?>
Now what i want to do is if a user logs in normally he should go to the default page after login but if he clicks the link then the user should be redirected to the same page after login and not the de开发者_开发知识库fault page.The URL of the page from which the user is redirected to the login page after clicking the link can be fetched by the following way
<?php echo AppController::AuctionLinkFlat($auction['Auction']['id'], $auction['Product']['title']);?>
How will i be able to do it? I have no idea how and what to do. Please suggest me some solution.
Add to beforeFilter in the user controller:
function beforeFilter() {
$this->Auth->autoRedirect = false;
parent::beforeFilter();
}
You can also replace the redirect with this to the login method of your user controller:
$this->redirect($this->Auth->redirect());
精彩评论