首页
/ PHP SharePoint Lists API 技术文档

PHP SharePoint Lists API 技术文档

2024-12-25 16:03:45作者:劳婵绚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
22
6
docsdocs
OpenHarmony documentation | OpenHarmony开发者文档
Dockerfile
165
2.05 K
nop-entropynop-entropy
Nop Platform 2.0是基于可逆计算理论实现的采用面向语言编程范式的新一代低代码开发平台,包含基于全新原理从零开始研发的GraphQL引擎、ORM引擎、工作流引擎、报表引擎、规则引擎、批处理引引擎等完整设计。nop-entropy是它的后端部分,采用java语言实现,可选择集成Spring框架或者Quarkus框架。中小企业可以免费商用
Java
8
0
openHiTLS-examplesopenHiTLS-examples
本仓将为广大高校开发者提供开源实践和创新开发平台,收集和展示openHiTLS示例代码及创新应用,欢迎大家投稿,让全世界看到您的精巧密码实现设计,也让更多人通过您的优秀成果,理解、喜爱上密码技术。
C
85
561
leetcodeleetcode
🔥LeetCode solutions in any programming language | 多种编程语言实现 LeetCode、《剑指 Offer(第 2 版)》、《程序员面试金典(第 6 版)》题解
Java
60
17
apintoapinto
基于golang开发的网关。具有各种插件,可以自行扩展,即插即用。此外,它可以快速帮助企业管理API服务,提高API服务的稳定性和安全性。
Go
22
0
cjoycjoy
一个高性能、可扩展、轻量、省心的仓颉应用开发框架。IoC,Rest,宏路由,Json,中间件,参数绑定与校验,文件上传下载,OAuth2,MCP......
Cangjie
94
15
ohos_react_nativeohos_react_native
React Native鸿蒙化仓库
C++
199
279
giteagitea
喝着茶写代码!最易用的自托管一站式代码托管平台,包含Git托管,代码审查,团队协作,软件包和CI/CD。
Go
17
0
RuoYi-Vue3RuoYi-Vue3
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
954
564