lexprodsas/contao-content-api-bundle
Composer 安装命令:
composer require lexprodsas/contao-content-api-bundle
包简介
Access Contao content via an easy to use JSON-API
README 文档
README
We at Die Schittigs love Contao, but the web moves forward and static HTML templating just doesn't cut it anymore. Thus we came up with an easily digestible JSON-API to access Contao content via JavaScript (or anything else that can handle JSON).
With the Contao Content API it is possible to write the entire Frontend of your website in React.js, Angular, vue, or any other JS-framework. All while still using the great Contao Backend.
Requirements
You'll need an up-and-running Contao 4.4.x installation. Please note that the API is not compatible with Contao 3.x.
Installation
Install composer if you haven't already, enter this command in the main directory of your Contao installation:
composer require dieschittigs/contao-content-api
Contao Content API is now installed and ready to use.
Usage
Once installed, the following routes are available:
/api/sitemap
Gets the sitemap including the root pages.
/api/sitemap/flat
Gets all pages as key value pairings where the key is the URL.
/api/urls[?file=sitemap]
Gets all URLs from the generated sitemap XML(s). If you define a file, only that XML will be parsed.
/api/page?url=/about/team.html
Gets the page, including all articles and contents at the url.
/api/newsreader?url=/news/detail/new-website.html
Gets the news reader content from the url
/api/?url=/page/or/newsarticle.html
Tries to get the page at the url, and contents from any reader
/api/user
Gets the logged-in frontend user, if available.
/api/module?id=5
Gets the content of a module by id
/api/text?file=tl_news,modules
Gets the content of a language file by filename(s)
/api/file?path=files/uploads&depth=2
Gets the file or directory at path and also it's children, limited by depth
All routes also take the additional lang parameter (e.g. ?lang=de). If you
need to override the language.
Configuration
Disabling the API
Edit your parameters.yml.
parameters:
…
content_api_enabled:
false
…
The API routes are now all disabled. This may be helpful if you only want to use the classes included in the bundle.
Response headers
Edit your parameters.yml.
parameters:
…
content_api_headers:
'Access-Control-Allow-Origin': 'https://mysite.org'
…
These headers will be added to all responses from the API.
Custom readers
Contao has the concept of Reader Module (e.g. News Reader). These can be
inserted anywhere inside of an article where they read the URL to display
their contents. If you want to add additional Reader Modules, you can do
so by adding them in your parameters.yml.
parameters:
…
content_api_readers:
newsreader: NewsModel
blogreader: BlogModel
…
Please note that the second parameter is the model class, not the module class. The new reader is now available at
/api/blogreader?url=/blog/detail/on-the-topic.html
or, if you want to include the whole page, at
/api?url=/blog/detail/on-the-topic.html
Internally the API tries to instantiate the model with the alias found in the url.
It also tries to add all ContentModels it can find.
Hooks
We provide some basic hooks:
class Hooks{
// $GLOBALS['TL_HOOKS']['apiBeforeInit']
public static apiBeforeInit(Request $request){
return $request
}
// $GLOBALS['TL_HOOKS']['apiAfterInit']
public static apiAfterInit(Request $request){
return $request
}
// $GLOBALS['TL_HOOKS']['apiContaoJson']
public static apiContaoJson(ContaoJson $contaoJson, mixed $data){
if($data instanceof ContentModel){
$contaoJson->data = null;
// End of the line
return false;
}
// Do your thing, ContaoJson
return true;
}
// $GLOBALS['TL_HOOKS']['apiResponse']
public static apiResponse(mixed $data){
$data->tamperedWith = true;
return $data;
}
// $GLOBALS['TL_HOOKS']['apiModuleGenerated']
public static function apiModuleGenerated(ApiModule $module, string $moduleClass)
{
// Override the way certain modules are handled
if ($moduleClass != 'Contao\ModuleBlogList') {
return;
}
$_module = new ModuleBlogList($module->model, null);
$module->items = $_module->fetchItems(
$module->category
);
}
}
Documentation
The classes crafted for the API might be a good starting point if you want to build anything on top of Contao.
Contribution
Bug reports and pull requests are very welcome :)
© Die Schittigs GmbH 2019
lexprodsas/contao-content-api-bundle 适用场景与选型建议
lexprodsas/contao-content-api-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 07 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「api」 「bundle」 「contao」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lexprodsas/contao-content-api-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lexprodsas/contao-content-api-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lexprodsas/contao-content-api-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
ext-json wrapper with sane defaults
DMS Meetup API Bundle, enables Meetup API clients in services
统计信息
- 总下载量: 47
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-13