0

I have a link whose target i need to change depending on whether a user is logged in or not. If a user is logged in I direct him to a different page and If he is not I intend to show a dialog box that asks the user to log in before he can view the content..its a polite error message.

I would really appreciate if you people could tell me how do I go about it. If i can use a session-flash. I would want to use a dialog using some javascript though.

4

1 回答 1

0

Just check if they are logged in like you do in controllers.

if (AuthComponent::user()) {
  echo $this->Html->link('Admin Backend', array(
    'controller' => 'users',
    'action' => 'backend'
  ));
} else {
  echo $this->Js->link('Admin Backend', array(
    'controller' => 'users',
    'action' => 'login'
  ), array(
    'data-modal' => 'true' // or however your code looks for modals
  ));
}

(This is for Cake 2.x and assumes you have javascript to handle creating a modal.)

于 2012-05-29T14:28:36.760 回答