ECJiaWiki:Api开发流程和规范
跳到导航
跳到搜索
配置文件
xxx/content/configs/api.php xxx/sites/api/content/configs/api.php(不是每个项目都有)
配置文件格式
'shop/info' => 'article::shop/info',// 接口名称 => appname::文件夹名称/文件名(可参考目录图)
目录位置
依赖关系
- app api
- config api.php
命名规范
xxx_module.class.php
代码示例
接口名称:shop/info 目录位置:article/modules/shop/info_module.class.php
class info_module extends api_front implements api_interface {
public function handleRequest(\Royalcms\Component\HttpKernel\Request $request) {
$article_db = RC_DB::table('article');
$article_db->where('cat_id' , '=', 0);
$article_db->where('content' , '<>', '');
$article_db->where('title' , '<>', '');
$cat_id = 0;
$cache_article_key = 'article_list_'.$cat_id;
$cache_id = sprintf('%X', crc32($cache_article_key));
$orm_article_db = RC_Model::model('article/orm_article_model');
$list = $orm_article_db->get_cache_item($cache_id);
if (empty($list)) {
$res = $article_db->get();
if (!empty($res)) {
$list = array();
foreach ($res as $row) {
$list[] = array(
'id' => $row['article_id'],
'image' => !empty($row['file_url']) ? RC_Upload::upload_url($row['file_url']) : '',
'title' => $row['title'],
);
}
}
$orm_article_db->set_cache_item($cache_id, $list);
}
return $list;
}
}
测试工具
https://testapi.ecjia.com/sites/cityo2o/