首页
/ PHP SharePoint Lists API 技术文档

PHP SharePoint Lists API 技术文档

2024-12-25 03:29:21作者:劳婵绚Shirley

1. 安装指南

使用 Composer 安装

如果你使用 Composer,只需将 thybag/php-sharepoint-lists-api 添加到你的 composer.json 文件中,然后运行 composer install

{
    "require": {
        "thybag/php-sharepoint-lists-api": "dev-master"
    }
}

手动安装

如果你不使用 Composer,可以手动下载 SharePointAPI 文件,并在你的项目中包含顶层的 SharePointAPI.php 类。

2. 项目的使用说明

创建 SharePointAPI 对象

在使用 PHP SharePoint Lists API 之前,你需要一个具有所需列表权限的有效用户/服务账户。

对于大多数 SharePoint 安装,你可以使用以下方式创建 API 实例:

use Thybag\SharePointAPI;
$sp = new SharePointAPI('<username>', '<password>', '<path_to_WSDL>');

如果你的安装需要 NTLM 认证,可以使用以下方式:

use Thybag\SharePointAPI;
$sp = new SharePointAPI('<username>', '<password>', '<path_to_WSDL>', 'NTLM');

SharePoint Online 用户必须使用以下方式:

use Thybag\SharePointAPI;
$sp = new SharePointAPI('<username>', '<password>', '<path_to_WSDL>', 'SPONLINE');

所有方法默认返回数组。可以使用 SetReturnType 指定结果应作为对象返回。

3. 项目API使用文档

读取列表数据

返回列表中的所有项目

$sp->read('<list_name>');

$sp->query('<list_name>')->get();

返回列表中的前10项

$sp->read('<list_name>', 10);

$sp->query('<list_name>')->limit(10)->get();

返回姓氏为 "smith" 的所有项目

$sp->read('<list_name>', NULL, array('surname'=>'smith'));

$sp->query('<list_name>')->where('surname', '=', 'smith')->get();

返回姓氏为 "smith" 且年龄为 40 的前5项

$sp->read('<list_name>', 5, array('surname'=>'smith','age'=>40));

$sp->query('<list_name>')->where('surname', '=', 'smith')->and_where('age', '=', '40')->limit(5)->get();

使用特定视图返回姓氏为 "smith" 的前10项

$sp->read('<list_name>', 10, array('surname'=>'smith','age'=>40),'{0FAKE-GUID001-1001001-10001}');

$sp->query('<list_name>')->where('surname', '=', 'smith')->and_where('age', '=', '40')->limit(10)->using('{0FAKE-GUID001-1001001-10001}')->get();

返回姓氏为 "smith" 且按年龄排序的前10项

$sp->read('<list_name>', 10, array('surname'=>'smith'), NULL, array('age' => 'desc'));

$sp->query('<list_name>')->where('surname', '=', 'smith')->limit(10)->sort('age','DESC')->get();

返回前5项,包括 "favroite_cake" 和 "favorite_animal" 列

$sp->read('<list_name>', 5, NULL, array("favroite_cake", "favorite_animal"));

$sp->query('<list_name>')->fields(array("favroite_cake", "favorite_animal"))->limit(5)->get();

查询列表

查询方法可以用于需要指定复杂查询的情况。查询是通过一系列(希望是表达性的)伪 SQL 方法构建的。

例如,如果你想查询一个宠物列表并返回所有年龄小于5岁的狗(按年龄排序),你可以使用:

$sp->query('list of pets')->where('type','=','dog')->and_where('age','<','5')->sort('age','ASC')->get();

如果你想获取前10个宠物,它们要么是猫要么是仓鼠,你可以使用:

$sp->query('list of pets')->where('type','=','cat')->or_where('type','=','hamster')->limit(10)->get();

添加到列表

要向列表中添加新项目,可以使用 writeaddinsert 方法(所有方法功能相同)。创建一个包含 forename、surname、age 和 phone 列的新记录可能如下所示:

$sp->write('<list_name>', array('forename'=>'Bob','surname' =>'Smith', 'age'=>40, 'phone'=>'(00000) 000000' ));

你还可以通过以下方式一起运行多个写操作:

$sp->writeMultiple('<list_name>', array(
    array('forename' => 'James'),
    array('forename' => 'Steve')
));

编辑行

要编辑一行,你需要其 ID。假设上面的行有 ID 5,我们可以将 Bob 的名字改为 James:

$sp->update('<list_name>','5', array('forename'=>'James'));

write 方法一样,你也可以通过以下方式一起运行多个更新操作:

$sp->updateMultiple('<list_name>', array(
    array('ID'=>5,'job'=>'Intern'),
    array('ID'=>6,'job'=>'Intern')
));

删除行

要删除一行,需要其 ID 和列表名称。要删除 ID 为 5 的 James 记录,你可以使用:

$sp->delete('<list_name>', '5');

如果你希望一次删除多个记录,也可以将 ID 数组传递给 deleteMultiple 方法:

$sp->deleteMultiple('<list_name>', array('6','7','8'));

4. 项目安装方式

使用 Composer 安装

{
    "require": {
        "thybag/php-sharepoint-lists-api": "dev-master"
    }
}

手动安装

手动下载 SharePointAPI 文件,并在你的项目中包含顶层的 SharePointAPI.php 类。

登录后查看全文
热门项目推荐

项目优选

收起
kernelkernel
deepin linux kernel
C
27
11
docsdocs
OpenHarmony documentation | OpenHarmony开发者文档
Dockerfile
466
3.47 K
nop-entropynop-entropy
Nop Platform 2.0是基于可逆计算理论实现的采用面向语言编程范式的新一代低代码开发平台,包含基于全新原理从零开始研发的GraphQL引擎、ORM引擎、工作流引擎、报表引擎、规则引擎、批处理引引擎等完整设计。nop-entropy是它的后端部分,采用java语言实现,可选择集成Spring框架或者Quarkus框架。中小企业可以免费商用
Java
10
1
leetcodeleetcode
🔥LeetCode solutions in any programming language | 多种编程语言实现 LeetCode、《剑指 Offer(第 2 版)》、《程序员面试金典(第 6 版)》题解
Java
65
19
flutter_flutterflutter_flutter
暂无简介
Dart
715
172
giteagitea
喝着茶写代码!最易用的自托管一站式代码托管平台,包含Git托管,代码审查,团队协作,软件包和CI/CD。
Go
23
0
kernelkernel
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
203
81
RuoYi-Vue3RuoYi-Vue3
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
1.26 K
695
rainbondrainbond
无需学习 Kubernetes 的容器平台,在 Kubernetes 上构建、部署、组装和管理应用,无需 K8s 专业知识,全流程图形化管理
Go
15
1
apintoapinto
基于golang开发的网关。具有各种插件,可以自行扩展,即插即用。此外,它可以快速帮助企业管理API服务,提高API服务的稳定性和安全性。
Go
22
1