With this code i have an obviously
Undefined variable: user
So, my question is how can I access the $user in add.ctp? Probably this is basic but I am new in Cake. Or the correct way is call the method like:
$user = new UsersController();
$user -> add();
?
UsersController.php
public function add() {
...
$user = $facebook->getUser();
...
}
add.ctp
<?php if ($user){ ?>
<a href="<?php echo $logoutUrl; ?>">Logout</a>
<?php }else{ ?>
<a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
<?php } ?>
You need to set it:
See http://book.cakephp.org/2.0/en/controllers.html#interacting-with-views