Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
README.md
ra-news-class.php
ra-news-demo.php

README.md

PHP API FOR NEWS

Is a class that can simplify your work to create your custom blog page or a news website.

How it works?

  1. Include the class in your PHP script. Example: include "ra-news-class.php";
  2. Make sure that you have properly created a database or atleast you have existing one.
      After that you have to set the database variables in the following way:
    • $server_name = $_YOUR_SERVER_NAME;
    • $db_name = $_YOUR_DATABASE_NAME;
    • $db_user = $_THE_USER_OF_YOUR_DATABASE;
    • $db_pass = $_THE_PASSWORD_OF_YOUR_DATABASE;
    • $stories_table: The table where we are going to store the stories. By default it is "ra_news_stories".
  3. Once you've set the Database & the DB variables you are ready to call the RA_NEWS class. Example: $news_demo = new RA_NEWS( true, $server_name, $db_name, $db_user, $db_pass );
      The class takes 6 arguments:
    • $debug - By default it is set to false but if it's true the class will return the errors if any occurs.
    • $server_name - The name of the HOST SERVER.
    • $db_name - The name of the Database.
    • $db_user - The Database user.
    • $db_pass - The password of the Database user.
    • $stories_table - The table which to be created / used for the stories.
        Structure of the stories table:
        id int NOT NULL AUTO_INCREMENT,
        story_title LONGTEXT,
        story_publish_date DATE,
        story_text LONGTEXT,
        PRIMARY KEY (id)
  4. Now you are ready to play around with the class methods.
      The methods are:
    • initialize_db() - Is used to create the table for the news in the database if we already don't have it.
    • add_story( $title_, $content_, $date_ = "" ) - Is used to create a new story in the News table. A specific $title_, $content_ & $date_ can be provided as arguments.
    • edit_story( $id, $title_ = "", $content_ = "", $date_ = "" ) - Is used to edit a story that already exists in the DB. The ID selector of the specific story can be provided by the $id var and the new title, content & date can be provided by $title_, $content_ & $date_. Note: If they are empty the specific field won't be updated in the DB.
    • delete_story( $id ) - Is used to delete a story from the DB. The ID selector of the specific story can be provided by the $id var.
    • get_story( $id ) - Is used to return story from the DB. The ID selector of the specific story can be provided by the $id var. Ther returned result is in JSON object.

Live demo can be found here.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.