且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查用户是否使用Zend Framework登录?

更新时间:2023-12-04 08:50:34

您要使用的工具是 Zend_Auth ,当您掌握它时,它很容易使用.

The tool you want to use is Zend_Auth which is quite easy to use when you get the hang of it.

检查用户是否已登录可以很简单:-

Checking if a user is logged in can be as simple as:-

$auth = Zend_Auth::getInstance();
if($auth->hasIdentity()) $loggedIn = true;

请参见罗伯·艾伦(Rob Allen)出色的Zend Auth入门教程.

我使用的方法是建立一个用户类,该类负责授权和访问控制,并将其作为

The method I use is to set up a user class that looks after authorisation and access control and inject it into my application as an Action Helper, so that in any of my controllers I can just do:-

$this->user->checkSomething();

授权部分需要影响您不想公开的站点的所有部分,并且每个受影响的控制器都需要检查用户是否已登录.对于访问控制,这是针对每个角色/每个资源完成的取决于您需要的细粒度.请参见 ACL 和 AUTH .

The authorisation part needs to affect all the parts of your site which you don't want public and each affected controller needs to check that the user is logged in. For access control, that is done on a per role/per resource basis depending on how fine grained you need to be.See ACL and AUTH in the manual.