Welcome Guest, Not a member yet? Register   Sign In
Working on a REST API, critique requested
#7

[eluser]Yorick Peterse[/eluser]
[quote author="Phil Sturgeon" date="1243629443"]Also, your Model_api is incredibly restrictive. What if I want to do complicated calls? Why is there any need for that model at all? Ever?

I think I make be looking at your code slightly different to you. If these are meant to be controllers and models and not a new controller type and model type that others will inherit, this almost makes sense.

If these are meant to be inherited by other models and controllers, this is a really bad method ^_^[/quote]

For now I'll keep the models as they are, I did make some changes to them (see below). But how would you do it without the model ? That will make you end up having data layer related code in your controller.


Model


Code:
<?php

class Model_api extends Model {
    
    // Constructor function
    function __construct() {
    parent::Model();
    }
    // Function to output data in XML or JSON
    function getData($table,$id,$format) {
    // Create the query
    if($id != null) {
        $query = $this->db->get_where("$table",array('id' => $id));
    }
    else {
        $query = $this->db->get("$table");
    }
    
    // Convert the array to the format
    $results = $query->result();
    
    echo $this->getXML($results);

    }
    
    // Function to store the data that was sent using an HTTP request.
    function postData($table,$data) {
    
    }
    
    // Function to update existing data
    function putData($table,$id,$data) {
    
    }
    
    // Function to delete data
    function deleteData($table,$id) {
    
    }
    
    /**
     * Converting data
     *
     * 2 main functions, getXML and getJSON. These functions will convert an array to either XML or JSON
     */
    
    // Function to convert an array to XML format
    private function getXML($array) {
    // First check if the data is actually an array
    if(is_array($array)) {
        //...Convert it...
    }
    // Return false, in case the $array variable isn't an array
    else {
        return false;
    }
    }
    
    // Function to convert an array to JSON format
    private function getJSON($array) {
    
    }
}
?>


Messages In This Thread
Working on a REST API, critique requested - by El Forum - 05-29-2009, 08:13 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:15 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:25 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:30 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:35 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:37 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:39 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:43 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:48 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:55 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 10:03 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 10:31 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 12:45 PM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 03:53 AM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 05:10 AM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 05:29 AM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 08:27 AM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 08:28 AM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 09:21 AM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 09:26 AM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 09:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB