Build a simple content management system using Yaapi and PHP

Source: Internet
Author: User
If you are a developer who is building a Web site with rich content, you may need to consider the following solutions, including (a) databases for content, (B) A template system that separates the GUI from the content. (c) it is used to maintain a user-friendly interface for data in the database, and (d) it controls the final appearance of the generated page. If you are a developer who is building a Web site with rich content, you may need to consider the following solutions, including () for the content database, (B) the template system that separates the GUI from the content, (c) The user-friendly interface for maintaining the data in the database, and (d) controls the final appearance of the generated page.



A very interesting solution that provides all of the above is the Yaapi, which is the abbreviation of the beginning of "Your Article Application Programming Interface (Your Article Application Programming Interface. It is a PHP class that provides built-in methods to access the content stored in the database. The management module is equipped with classes to assist in data management. This API is powerful enough to handle most common tasks required by the content management system (CMS.

Install
To install and use Yaapi, you need a Web server that supports PHP, such as Apache, PHP, and MySQL database server. You can download a Yaapi and decompress it to a location in the root directory of the server.

You also need to create a MySQL database to accommodate the data structure of the Yaapi. Use the yaapi in the source file. create the database in the SQL file, and then open the class constructor (article. class. in the php file), use the name and access parameters used for the database to update it.

Add content
To add content to a database, you must use http: // yaapi management module on your-server/Yaapi-root/admin/(replace "your-server" with the name of the server with Yaapi installed ", use the directory decompressed by Yaapi to replace "yaapi-root "). You need to use this management module to create (and delete) content categories, and then put the articles in these categories. The following is a brief table of fields you will encounter in this process:

Category: the Category of the document.
Section ID: If your article has two levels, use this parameter to define the second level.
Title: The Title of an article
Author (Author): Author of the article
Email (email): The email address of the author of the article
Permission: indicates whether the document is "licensed" and can be displayed.
Image: optional Image URLs related to articles
Content: Content of the article
A little note about the last project above: by inserting delimiters in the article text, Yaapi can split your large article into several small pages for display. See the following example:

Introduction of article here

# Intro #
Page 1 content here
# Page #
Page 2 content here
# Page #
Page 3 content here
# Page #
And so on...

Don't forget to confirm after entering the article, because only the confirmed article can be retrieved by API.
Search categories and lists


Now that you have put the content in the database, you can use the API to retrieve it and fill in a standard HTML template (you can modify this template to suit your website's design) it's time. List A contains the basic code of the template.

In the beginning, you can use Yaapi to retrieve the list of all articles in a specific category and display their titles, authors, and descriptions in the middle. List B contains the PHP code and the Yaapi call that implements this code. This code should be explained a little.

When using Yaapi, the first step is to instantiate the class object. this object then exposes the API methods and attributes for accessing the content in the database. To obtain the title list, you can use the Category ID. The latter can be passed through a URL or a default value. The Get_titles () method uses this Category ID to return an Associated array containing the article ID and (confirmed) article title in this category.

Then, the get_article () method will take a further step, iterate in the list of article IDs returned in the previous step, and return the objects representing each article. (Article) titles, Author details, and introductions are published as attributes of objects and can be retrieved using standard object attribute concepts. Note that the title of the article is further linked to a separate PHP script named article. php through the article ID object. This article will be introduced soon.


--------------------------------------------------------------------------------

Prompt
You can pass the optional second parameter to the get_article () method, that is, the page label, to return a special page of the article.


--------------------------------------------------------------------------------

To complete the work on this page, all you have to do is to get and print the list of available categories (remember, this list is required for the menu on your left ). You can use the get_categories () method to complete this job. this method returns a related array containing the category names and their respective IDs. List C contains the updates required by this script from list B.

In Figure A, you can see the final result:


Search article content
The display of the complete article is handled by the article. php script, which is called by the article ID. List D contains the script code, including support for page delimiters, which is achieved by allowing you to use the page number at the bottom of the page to jump to any page of the article.

The content of each page is retrieved using the get_article () method discussed earlier. The only difference is that the "content" attribute of the returned object will now save a specific page of the article, rather than an introduction.

Num_pages () is used to obtain the total number of pages of an article. This can be combined with a simple for () loop to generate a page number navigation bar and hyperlink. each of them can return to the same script and all have the same article ID, but different page IDs.

Figure B shows the output result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.