如何从外部PHP文件检查symfony 1.4中的isAuthenticated?

时间:2014-05-20 10:22:50

标签: php session symfony1 symfony-1.4

如何从外部PHP文件中检查 symfony 1.4 中的isAuthenticatedisLogged

位于/web/js/filemanager.php

的外部PHP文件

1 个答案:

答案 0 :(得分:0)

通过isAuthenticated到另一个外部php文件的唯一方法是传递sfUser类的对象

@应用程序/前端/模块/ indexAction.class.php

<?php

class modulenameAction extends sfAction
{
  public function execute($request)
  {
    $user = $this->getUser();

    $sample = new Sample();
    $sample
      ->setUser($user)
      ->setOtherFunction($blabla)
      ->setOtherFunction($blabla);

    if ($sample->result()) {
      return $this->renderText('Authenticated');
    } else return $this->renderText('Not authenticated');
  }
}

然后关于你的Sample类

<?php

class Sample
{
  private $user;

  public function setUser($user)
  {
    $this->user = $user;
    return $this;
  }

  public function result()
  {
    if ($this->user->isAuthenticated())
    {
      return true;
    }

    return false;
  }
}