Hongmu Notes
Home Program Notes Empire CMS – Simple API code for generating article content
Program Notes Empire cms

Empire CMS – Simple API code for generating article content

Empire CMS – Simple API code for generating article content

If you want to allow other websites to access your Empire CMS-powered site via an API endpoint, you can create an "api" folder within your root directory, then create an `index.php` file inside it and place the corresponding code inside. Once you access this file, you'll be able to view your articles!

20231126193946350-图片

Simple code demo

<?php
require('../class/connect.php');        //引入数据库配置文件和公共函数文件
require('../class/db_sql.php');        //引入数据库操作文件
$link=db_connect();                //连接MYSQL
$empire=new mysqlquery();        //声明数据库操作类

$file = 'id.txt';
$id = file_exists($file) ? file_get_contents($file) : 1;

$r=$empire->fetch1("select * from {$dbtbpre}ecms_news where id={$id}");
$data['code'] = 404;
if(!empty($r)){
    $r2=$empire->fetch1("select * from {$dbtbpre}ecms_news_data_{$r['stb']} where id={$r['id']}");
    if(!empty($r2)){
        $data['data']['id'] = $r['id'];
        $data['data']['title'] = $r['title'];
        $data['data']['content'] = $r2['newstext'];
        $data['code']   = 200;
    }
}

$id++;
file_put_contents($file,$id);
header("content-type:application/json;charset=utf-8");
echo json_encode($data);

db_close();                        //关闭MYSQL链接
$empire=null;                        //注消操作类变量

 

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

Empire CMS database statement & SQL statement format

Empire CMS database statement & SQL statement format Program Notes Empire cms

Introduction to Imperial CMS extended SQL program writing, basic examples of Imperial CMS database statements & SQL statement formats: Note: The following examples are based on placing PHP files in the system root directory. Example 1: Connect to MYSQL program. (a.php)<?php require('e/class/connect.php'); //Introduce database configuration files and public function files requ…
👁 351
Empire CMS obtains the system COOKIE variable function getcvar()

Empire CMS obtains the system COOKIE variable function getcvar() Program Notes Empire cms

Get the system COOKIE variable function syntax: getcvar($var,$ecms) Description: $var: is the variable name $ecms: 0 is to set the foreground COOKIE variable, 1 is to set the background COOKIE variable. This parameter can be omitted and defaults to 0. Usage example: getcvar('mlusername'), get the user name of the front-end login member getcvar('loginu...
👁 295
Empire CMS smart label call field collection

Empire CMS smart label call field collection Program Notes Empire cms

Collect and classify all fields that support smart tag calls into Empire CMS smart tags: [e:loop={column ID/topic ID, number of items displayed, operation type, only display pictures with titles, additional SQL conditions, display sorting}] Template code content [/e:loop] Calling time: <?=date('m-d',$bqr[newstime])?> <?=dat…
👁 3749

Recommended reading

jQuery AJAX Tutorial: Integrating with Web Forms (Frontend + Backend PHP)

jQuery AJAX Tutorial: Integrating with Web Forms (Frontend + Backend PHP) Language Notes JavaScript

Communicating with the server is easy using jQuery's ajax functions, and the form can send data to the server. Using them together allows for dynamically loaded and more interactive web pages. Below is a simple tutorial showing how to use jQuery's ajax functions to send form data to the server. Introduce jQuery library Introduce jQuery library into the page so that you can use jQuery's aja...
👁 115
(PC+WAP) Embroidery Website – PBootCMS Template; Download Source Code for Traditional Handicrafts Websites – 0083

(PC+WAP) Embroidery Website – PBootCMS Template; Download Source Code for Traditional Handicrafts Websites – 0083 Practical Collection pbootcms Template

This PbootCMS template is ideal for the embroidery, needlework, and traditional handicraft industries, supporting access via both PC and WAP devices. Its classical and elegant design beautifully showcases the aesthetic beauty and cultural heritage of embroidery craftsmanship. This template helps traditional handicraft businesses showcase their products online, preserve their craft traditions, and expand their market reach. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password:...
👁 58
(Adaptive Mobile Version) Responsive Spectrometer Electronic Instrumentation Company – PBootCMS Website Template; Download Source Code for Precision Instrumentation Websites – 0713

(Adaptive Mobile Version) Responsive Spectrometer Electronic Instrumentation Company – PBootCMS Website Template; Download Source Code for Precision Instrumentation Websites – 0713 Practical Collection pbootcms Template

A responsive website template for an optical spectrometer and electronic instrumentation company (PbootCMS), compatible with both PC and WAP devices. The design features a modern, technical aesthetic, making it ideal for showcasing high-end equipment such as spectrometers and analytical instruments. This template helps precision instrument manufacturers showcase their product performance and technical specifications online, attracting customers from both the scientific research and industrial sectors. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extract...
👁 42
Responsive bilingual (Chinese/English) tea ceremony website template – 0176

Responsive bilingual (Chinese/English) tea ceremony website template – 0176 Practical Collection Yiyou template

An eYou CMS responsive website template designed for the bilingual (Chinese/English) tea industry and tea ceremony sector. Its classical yet international design style effectively showcases tea products, tea ceremony culture, export advantages, and brand stories. Multi-language support enables tea brands to convey their cultural heritage across global markets. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for eYou CMS...
👁 56
Responsive Science and Engineering Experimental Foreign Language School College Website Template 0833

Responsive Science and Engineering Experimental Foreign Language School College Website Template 0833 Practical Collection Yiyou template

An eYouCMS responsive website template designed for science and engineering institutions, laboratories, foreign language schools, and academic departments. Its technology-driven design is ideal for showcasing laboratory facilities, foreign language teaching programs, research achievements, and admissions information, helping science and foreign language-focused institutions effectively highlight their unique strengths online. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for eYouCMS | eYouCMS...
👁 53
(PC + WAP) Green QQ Blog Space – PBootCMS Template; Download source code for an elegant article-based blog website – 0084

(PC + WAP) Green QQ Blog Space – PBootCMS Template; Download source code for an elegant article-based blog website – 0084 Practical Collection pbootcms Template

A green-themed QQ Diary and Space Blogging Template, developed using PbootCMS, supports both PC and WAP devices. Its fresh and artistic design makes it ideal for publishing beautiful essays, emotional journals, or personal reflections. The user-friendly reading experience helps individual bloggers or literature enthusiasts create their own digital space. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: a...
👁 60