如何在href中使用PHP变量?

时间:2016-01-17 23:04:52

标签: php html

我在PHP中为一个项目创建了一个FacebookConnect类。它运行良好,但问题是我无法正确使用<?php /* * This file is part of the FOSUserBundle package. * * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace FOS\UserBundle\Controller; use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\Exception\AccountStatusException; use FOS\UserBundle\Model\UserInterface; /** * Controller managing the registration * * @author Thibault Duplessis <thibault.duplessis@gmail.com> * @author Christophe Coevoet <stof@notk.org> */ class RegistrationController extends ContainerAware { /** * Receive the confirmation token from user email provider, login the user */ public function confirmAction($token) { $user = $this->container->get('fos_user.user_manager')->findUserByConfirmationToken($token); if (null === $user) { throw new NotFoundHttpException(sprintf('The user with confirmation token "%s" does not exist', $token)); } $user->setConfirmationToken(null); $user->setEnabled(false); $user->setLastLogin(new \DateTime()); $this->container->get('fos_user.user_manager')->updateUser($user); $response = new RedirectResponse($this->container->get('router')->generate('fos_user_registration_confirmed')); $this->authenticateUser($user, $response); return $response; } }

href

我试图通过<a href="index.php?module=compte&action=loginFacebook" class="fb-login-button">Connect with fb</a> 中的某个控制器调用方法。我想这样做,当我点击按钮时,它会启动登录过程。

href

事实上,我想直接在public function _loginFacebook() { $connect = new FacebookConnect($appid,$app_secret); $user = $connect->connect('http://localhost/washare/?site=public&module=Compte&action=profil'); if (is_string($user)) { return $user; } } 中使用$user变量(这是一个重定向网址),但我猜我做错了。有人能帮助我吗?

1 个答案:

答案 0 :(得分:-1)

函数_loginFacebook被调用?如果是这样,代码的哪一部分实现了? 您可以使用标题在php上重定向。

<?php    
header('Location: mapeamento.php');    
?>