Creating api controller - Kaoschuks/php-angularJS GitHub Wiki

*** Need To Know **

  • Logics are modules in which makes up the api
  • A Logic can use more than one Trait example e.g Blog uses traits manager,category,review,files for various functionality to be added for that module

*** Creating Traits *** e.g

#!php

<?php

// innocent this is a not complated work 

includeFile('api/model/DBManager.php');

Abstract Class Test implements IController
{
    public static function process($func = null)
    {
        DBManager::$table = "test"; // Database table
        DBManager::$key[0] = 'name'; //Key to check of data exists
        Manager::$map = array('name', 'description', 'category', 'date', 'image'); /// entities for module
        return (in_array($func, get_class_methods(__CLASS__)))
                ? self::$func()                  // Find any function in Class and calls 
                : Manager::manager_init($func);  ///Simple crud operation using the TManager trait
    }

    public static function Search()
    {
        DBManager::$key = array('name', 'category', 'itemid'); // keys for searching
        foreach(DBManager::$key as $index => $values)
        {
            DBManager::$data[$values] = $_POST['search'];
        }
        return General::Search();
    }

    private static function Category()
    {
        return (count(explode('/', $_GET['controller'])) === 2)
                ? Category::category_init(__CLASS__)
                : self::process(@ explode('/', $_GET['controller'])[2]);
    }

    private function Review()
    {
        return Comments::comments_init(null);  //Uses the TComment trait to manage review for this Module
    }
}

?>