EzDevInfo.com

tonic

RESTful PHP library/framework Tonic: The RESTful Web App PHP Micro-Framework

how to map url with method in tonic?

i want to map the url with tonic, how can i do that? is there any particular doc where i can? except it's API doc, because i have read it's API there is no any docs about that?

for example here is my class

    /**
 * Display and process a HTML form via a HTTP POST request
 *
 * This page outputs a simple HTML form and gathers the POSTed data
 *
 *
 *
 *
 * @uri /example/getExample/:name     
 * @uri /example/getExample/         
 * 
 * @uri /Example/:name
 * 
 */
 class example extend Resource{

    /**
     *  
     * Handle a GET request for this resource
     * @method GET
     * @param Request $name
     * @return str
     */
    function getExamplemethod1($name=null) {
        return json_encode(array('status'=>'done method 2'));
    }

    /**
     * 
     * Handle a POST request for this resource
     * @method GET
     * @param Request $name
     * @return str
     */
    function getExamplemethod2($name=null) {
        if($name == null){
            return json_encode(array('status'=>'done1'));
        }
        else{
            return json_encode(array('status'=>'done1', 'name'=>$name));
        }
    }



 }

i want to call the method in the url how can i do that? any body can help me to do that, million ton thanks in advnace.


Source: (StackOverflow)

How to get the original URI extension using PHP Tonic?

I'm developing a REST API using PHP and Tonic. The framework has a fine feature which is the inference of the Content-Type based on the extension of the URI requested. In the case of the service I'm developing, it's important to know the full name of the requested file.

If I use the following code:

$this->request->uri;

For a URI such as http://service.com/image1.jpg, all I get is image1.

I could get the information I need going straight through $_SERVER['REQUEST_URI'], but I'd like to use the facilities of the framework for this (should there be any). Also, I found the documentation pretty poor, so, any doc links will be appretiated as well. Thanks.


Source: (StackOverflow)

Advertisements

encode of REST parameter with "/" not working

I'm running a REST service on an URI likewise to

localhost/1.0/json/host/:list/

where :list is the parameter to search for. The corresponding PHP function (using Tonic)

public function get($list) {
        $list = urldecode($list);
        $list = mysql_real_escape_string($list);

is decoding and escaping any input provided. This works as long as no input has to really encoded.

The corresponding js application uses encodeURIcomponent to encode an input made in an input box

var selectedList = encodeURIComponent($('#SelectList').val());

and fires a jQuery.get to the aforementioned REST resource

$.get("http://localhost/rest/1.0/json/host/"+ selectedList + "/", function(data) {

If an input like '923/50' is selected in the input box the parameter is properly encoded

XHR at "localhost/rest/1.0/json/host/923%2F05/"

But it is still impossible to get the records connected to this param out of my db. I get 404's all the time. So my guessing is that it is not possible to encode chars like "/".

What should i do to resolve this?


Source: (StackOverflow)

Tonic.PHP on having "/resource" and "/resource/id" URL's

I'm trying to get the URL "/videoGame" to run "listAllVideoGames" method and "/videoGame/#" (Where # is a number) to run "getVideoGame" method. Changing priorities with "@priority" annotation I can make both URL's call one or the other but can't find the way to do what I described.

/**
 * @uri /videoGame
 * @uri /videoGame/:id
 */
class VideoGame extends Resource{

    protected function getDao(){
        return new VideoGameDao();
    }

    /**
     * @uri /videoGame
     * @json
     * @provides application/json
     * @method GET
     */
    public function listAllVideoGames(){
        return new Response(Response::OK,$this->dao->getAllVideoGames());
    }

    /**
     * @uri /videoGame/:id
     * @json
     * @provides application/json
     * @method GET
     */
    public function getVideoGame($id){
        $vg = $this->dao->getVideoGame($id);
        if ($vg){
            return new Response(Response::OK,$vg);
        }else{
            throw new NotFoundException();
        }
    }
}

Source: (StackOverflow)

how to handle a "get" request ending with an extension

I have this request, well defined and working. Here is a snippet:

/**
 * @uri /reports/data/dealerRequests
 */
class RepDealerRequestsResource extends Resource {

   /**
     * @method GET
     * @json
     * @provides text/json
     * @return Tonic\Response
     */
    function get() {
        //code code code
    }

}

If I point my browser to <baseurl>/reports/data/dealerRequests I get exactly what I expect. But - here is the tricky part - if I request either <baseurl>/reports/data/dealerRequests.xml or <baseurl>/reports/data/dealerRequests.json my get() function is called anyway and I get the same result!

What I would like to do is:

  • Finding a way to check the extension required, possibly creating a new method for each extension required. Any annotation I don't know could help me on this?
  • Add new extensions that are not allowed by default (i.e. .csv)

Thanks


Source: (StackOverflow)

Apache 2.2 ignores .htaccess if Server Directory : {AllowOverride : None} and VirtualHost : { AllowOverride : all}

First of all, I'vre read every question about this kind of topic but except one of them, isn't replied.

I have an Apache 2.2 Server

Server
|-foo
|-bar
|-piz
|-target
 |-www
 |-rest_service

And i'm implementing a PHP-REST Service on /target/rest_service. For it, I'm installing Slim or Tonic Framework, and neither of them works. I studied it for a time, and I think that the problem is because de .htaccess file isn't being readed from Apache, so, Apache doesn't redirect .../rest_service/question/data to .../rest_service/index.php

httpd.conf

...
#LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
...
<VirtualHost *:8080>
    DocumentRoot "E:\me\workspace\target\rest_service"  
    #ErrorLog "logs/mysite.com-error.log"
    #CustomLog "logs/mysite.com-access.log" combined
RewriteLog "E:\me\workspace\target\rest_service\rewrite.log"
    <Directory "/target/rest_service">  
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

.htaccess on "E:\me\workspace\target\rest_service\" ( from Slim Framework )

RewriteEngine On

# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
#RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

I just want to redirect every path up (!or below) .../rest_service/ to .../rest_service/index.php so .../rest_service/users/7 is being proccesed by .../rest_service/index.php

Lot of thanks

EDIT! - MORE INFO:

server.log

[Thu May 30 10:20:13 2013] [notice] Child 2820: Starting 64 worker threads.
[Thu May 30 10:20:13 2013] [notice] Child 2820: Starting thread to listen on port 8080.
[Thu May 30 10:20:13 2013] [notice] Child 2820: Starting thread to listen on port 80.
[Thu May 30 10:20:13 2013] [notice] Child 2820: Starting thread to listen on port 8888.
[Thu May 30 10:20:13 2013] [notice] Child 4196: All worker threads have exited.
[Thu May 30 10:20:13 2013] [notice] Child 4196: Child process is exiting
[Thu May 30 10:20:18 2013] [error] [client 127.0.0.1] File does not exist: E:/.../rest_service/users/7

rewrite.log -> nothing!

EDIT - Partial Solution!

At the starting point, at the base Directory (localhost/), I have AllowOverride to None, that's the reason why I'm enabling an VirtualHost, to have two different configs. (localhost/[ foo | bar | piz ]) and (localhost:port/).

IF I SET AllowOverride all IT WORKS!, but, I want to have a configuration appart for the rest of the server. Is there any way?


Source: (StackOverflow)