如何检查用户是否使用Zend Framework登录? [英] How to check if user is logged with Zend Framework?

查看:78
本文介绍了如何检查用户是否使用Zend Framework登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Zend Framework,但是我对用法和概念有一些疑问.

I'm learning Zend Framework, but I have some doubts about the usage and the concepts.

我想检查用户是否已登录以允许访问所有页面.如果是,则显示页面,如果不是,则显示登录页面.

I want to check if the user is logged to allow access to all the pages. If it is, show the page, if not, display the login the page.

我主要的疑问是我需要使用什么来完成(Zend_Auth,Zend_Acl等)和检查用户是否已登录的位置(在每个控制器或框架会针对每个申请自动检查).

My main doubts are what I need to use to do this (Zend_Auth, Zend_Acl, etc) and where to check if the user is logged (in each controller or the framework automatically checks this for each requisition).

推荐答案

您要使用的工具是 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 和<手册中的href ="http://framework.zend.com/manual/en/zend.auth.html" rel ="nofollow"> 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.

这篇关于如何检查用户是否使用Zend Framework登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆