- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我刚开始使用 Apigility 和 oAuth2,我想知道在从数据库中获取信息时是否有可能获得当前经过身份验证的“已登录”用户。
我目前有以下代码:
/**
* Fetch all or a subset of resources
*
* @param array $params
* @return mixed
*/
public function fetchAll($params = array())
{
var_dump($params);
// Using Zend\Db's SQL abstraction
$sql = new \Zend\Db\Sql\Sql($this->db);
//I would like to get the currently logged in user here... but how?
$select = $sql->select('projects')->where(array('userid' => 1));;
// This provides paginated results for the given Select instance
$paged = new \Zend\Paginator\Adapter\DbSelect($select, $this->db);
// which we then pass to our collection
return new ProjectsCollection($paged);
}
我已经做了很多搜索,但我不知道如何访问用户信息或访问 token ,我是否需要为此解析请求 header ?
最佳答案
我也在找。我没有找到任何相关文件。但答案很简单:
资源类继承ZF\Rest\AbstractResourceListener
,其中已经有一个方法getIdentity
。
/**
* Fetch all or a subset of resources
*
* @param array $params
* @return mixed
*/
public function fetchAll($params = array())
{
// if user isn't authenticated return nothing
if(!$this->getIdentity() instanceof ZF\MvcAuth\Identity\AuthenticatedIdentity) {
return [];
}
// this array returyour query here using $userIdns the authentication info
// in this case we need the 'user_id'
$identityArray= $this->getIdentity()->getAuthenticationIdentity();
// note, by default user_id is the email (username column in oauth_users table)
$userId = $identityArray['user_id'];
// fetch all using $userId
}
您还可以在 RPC 服务中使用 getIdentity
。
我使用的是最新版本的 apigility。
关于php - 在 Apigility Resource 中获取当前用户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36722291/
我想整合Doctrine 2到 Apigility驱动 Zend Framework 2应用。 所以我安装了zfcampus/zf-apigility-doctrine $ composer requ
我想创建一个 Apigility REST 服务,它接受例如用户对象的 POST,该用户对象具有包含地址对象数组的字段。我可以在没有验证器的情况下定义字段并在我的代码中处理原始 JSON,但我想知道是
我意识到 Apigility UI 需要对/modules 目录和/config 目录的写入权限。我的问题是,它创建的子目录需要什么权限? 在我的例子中,它创建了 755 的子目录(例如/module
我正在尝试为 Apigility 服务编写一个子路由,在呈现 _self 链接之前,一切路由都很好。 GET http://host/api/service/parameter/gui/page {
在 Apigility 中可以设置 Hydrator对于每个 Entity -- 通过 Apigility UI 或直接在module.config.php ,例如: return array(
我对 Apigility 有疑问。 当我保存我的 REST 服务的文档时,只保存描述整个 REST 服务的字段。 例如,我正在尝试保存响应主体,但没有成功。 我在发帖前检查过的一些事情: 我禁用了 o
我有一个关于验证嵌套 json 数据的小问题。例如,我有类似的 PATCH 请求: { "awesome": "yes", "myObject": { "some_pr
如何创建到我的 data/database.db 的连接我仅通过一个配置获得此连接,但不能从同一文件 module.php 中的另一个配置获得此连接 在这段代码中就可以了 public functio
我使用 Apigility 创建了一个代码连接的 API。现在我正在使用标准的创建 stub 。在我的 PostResource 中有一个名为 fetchAll($params = array())
我正在使用 Apigility 和 Zend Framework 2 构建 REST API。在此 API 中,我有一个代码连接的 REST 服务,当我尝试删除实体时遇到奇怪的行为。我使用 Table
我即将开始使用 rest API 开发应用程序,我想使用 apigility。不幸的是,这个想法有一个问题。我找不到可靠的信息来源如何允许普通用户通过 oAuth 进行身份验证。 我需要提供对 ang
我正在使用 Apigility 构建我的 Rest API。 我想构建具有接收多个参数的能力。比如 http://mydomain.com/users/1/activities/4 我现在可以从这个页
我想在 Apigility Zend Framework 2 应用程序中构建错误处理和日志记录机制,并捕获和记录所有异常。 经过一番研究,我发现了一个堆栈溢出 answer有了一个解决方案,这似乎正好
我正在使用 Zend Framework 2 中的 Apigility 创建服务。根据 its tutorial它存储了我在 data/statuslib.php 中 POST 并从这里获取的所有数据
我刚开始使用 Apigility 和 oAuth2,我想知道在从数据库中获取信息时是否有可能获得当前经过身份验证的“已登录”用户。 我目前有以下代码: /** * Fetch all or a su
我尝试创建数据库连接服务,但不起作用我遇到错误 e.rest 尝试创建服务 enter image description here 我尝试使用此解决方案,但无法正常工作,出现相同的错误 "zfcam
我想问问你的想法或解决方案,如果我从我的请求中得出这个回应。 我一直在使用 Zend framework 2 和 Apigility for API Calls。 这是我用来从表 Calendar I
我有一个带有一些模块的 ZF2 应用程序。我想允许在我的应用程序中使用我现有的模块和 Apigility。 我尝试用 composer 安装这些模块: "require": { "php":
具有通用文件夹结构的通用 ZF2 应用程序的 phpunit.xml ... /phpunit /phpunit/phpunit.xml /module /module/Application /mo
作为敏捷 documentation ( REST Service Tutorial -> Create a REST Service -> [infobox] Code-Connected vs D
我是一名优秀的程序员,十分优秀!