Login   Register  
PHP Classes
elePHPant
Icontem

Wamp 2.0

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      REST Server  >  All threads  >  Wamp 2.0  >  (Un) Subscribe thread alerts  
Subject:Wamp 2.0
Summary:Nothing happen.
Messages:10
Author:KiosqueC
Date:2009-11-23 16:39:09
Update:2009-12-03 00:57:17
 

  1. Wamp 2.0   Reply   Report abuse  
Picture of KiosqueC
KiosqueC
2009-11-23 16:39:09
When I try to use example with Wamp 2.0, nothing happen: blank page, blank source.
With example 2 the result is: HTTP/1.1 404 NOT FOUND
I downloaded the zip file. I only changed some "<?" to "<?php".

My install:
C:\wamp\www\REST_Server for the *.class.php
and C:\wamp\www\REST_Server\example, C:\wamp\www\REST_Server\example2 and C:\wamp\www\REST_Server\tests for your other files.

I made no change on my wamp server.
http://localhost/REST_Server/example/ give me a blank page.

before I changed <? to <?php, the result was:

addMap("GET","/?","HomeController"); $rest->addMap("GET","/user","UserController"); $rest->addMap("POST","/user","UserController::insert"); // A specific method $rest->addMap("GET","/user/[a-zA-Z0-9]+","UserProfile"); echo $rest->execute(); ?>

I'm a newby for this REST. My goal is to set or extract values from an xml file (using keys and values) with the GET and PUT methods.

(Please excuse my bad English.)

  2. Re: Wamp 2.0   Reply   Report abuse  
Picture of Diogo Souza da Silva
Diogo Souza da Silva
2009-11-24 00:20:58 - In reply to message 1 from KiosqueC
Hi,

There are a few changes to example2 .htaccess and index.php depending on your directory structure:

http://github.com/diogok/restserver/blob/master/example2/ind ...

http://github.com/diogok/restserver/blob/master/example2/.ht ...

In .htaccess fix the "RewriteBase /restserver/example2/" to your directory: "RewriteBase /REST_Server/example2/".

Also, is your wamp server configured to display errors? If not, look on your httpd.conf file for the line with "error_reporting", it should be "error_reporting = E_ALL" .

  3. Re: Wamp 2.0   Reply   Report abuse  
Picture of KiosqueC
KiosqueC
2009-11-25 17:36:28 - In reply to message 2 from Diogo Souza da Silva
Example 1 runs, now.

In my own program, (something like example 1 + mysql) I made that request:

http://localhost/myhomedir/?q=/id/c3c13a41-cb88-3047-75f7-ff ...

where c3c13a41-cb88-3047-75f7-ff4786ba5187 is a primary key for an user in my SGBD.

The request returns the good datas, in xml format.

But...
"q" means nothing for my own program. "user/status" will be more interesting because my request has to display the status of an user whose id is "c3c13a41-cb88-3047-75f7-ff4786ba5187".

So, my request should be something like:

http://localhost/myhomedir/user/status/c3c13a41-cb88-3047-75 ...
(without the page.php name and without ?q=).

It seems to be possible with Rest, and/or with a rewritting of .htaccess.

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

Example 2 doesn't run for the moment, I'll try it soon (bad configuration on my PC, perhaps).

  4. Re: Wamp 2.0   Reply   Report abuse  
Picture of Diogo Souza da Silva
Diogo Souza da Silva
2009-11-26 00:39:02 - In reply to message 3 from KiosqueC
You are right, the "q" is to be used only when you can't use the .htaccess rewrite.

For the result you expect (/user/status/id) you will need to get .htaccess to work, like in the link in previous message, must like example2.

Do you get any error for example2? I am not used to wamp, but you need to enable the mod_rewrite and set "AllowOverride" to "all" in apache configuration.

  5. Re: Wamp 2.0   Reply   Report abuse  
Picture of KiosqueC
KiosqueC
2009-11-26 16:40:55 - In reply to message 4 from Diogo Souza da Silva
Now, my config.http is OK with_rewrite_module.
For instance, I can call my maj_status.php with that uri:

http://localhost/myhomerep/user/status/46ab11b6-dce7-caf0-fa ...

instead of:

http://localhost/myhomerep/maj_status.php?id=$1&status=$246a ...

(Not so good, I'll probably turn it in:
http://localhost/myhomerep/user/46ab11b6-dce7-caf0-fa97-c027 ...

My .htaccess:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /myhomerep/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^user/status/([a-zA-Z0-9\-]+)/(true|false)$ maj_status.php?id=$1&status=$2 [NC]
RewriteRule ^user/status/([a-zA-Z0-9\-]+)$ index.php?q=/id/$1 [NC]

I don't need Rest in this case, as you see.

... but I want to learn it.
So, I've try your example2:

The result is:

Homepage
null

So, var_Dump($param["user"]) is unknown. Something is missing, I suppose?

I run this url :
http://localhost/restserver/example2

(I renamed my repertory restserver after your first reply.)

My .htaccess (under example2 repertory) is:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /restserver/example2/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?q=/$1



  6. Re: Wamp 2.0   Reply   Report abuse  
Picture of Diogo Souza da Silva
Diogo Souza da Silva
2009-11-27 18:48:10 - In reply to message 5 from KiosqueC
Ops, my bad.

If you get to see the "Homepage" them it is right, it was supposed to be var_dump($params["user"]) instead of var_dump($param["user"]), in home.php .

  7. Re: Wamp 2.0   Reply   Report abuse  
Picture of KiosqueC
KiosqueC
2009-12-01 15:53:05 - In reply to message 6 from Diogo Souza da Silva
Example2: I always obtain "null".

In order to understand your programs, I put some flags:

Responses:
User in HomeController = New User
User in HomeView = New User
File in GenericView = templates/home.php
Props in GenericView = Array

var_dump of props:
array
0 =>
object(stdClass)[5]
public 'name' => string 'New User' (length=8)

Size of props in GenericView = 1

props is an array :
key "0" contains one another array for value, whose key "name" has "New User" for value.

props: Array ( [0] => stdClass Object ( [name] => New User ) )

... but within homepage, var_Dump($params["user"]) displays "null".

Is my url good?
http://localhost/restserver/example2

I tried http://localhost/restserver/example2/John/Doe or other parameters: result: file not found.

It's difficult for me to understand Rest, but I'm not so bad when I can modify some examples.
So I need basic ones for PUT, GET, POST, DELETE or other Rest instructions.

My true homepage will receive Rest URIs, like these :
(PUT) http://localhost/myrootdir/user/10/Smith/John/false (10 is John Smith's ID, false is his current status)
(GET) http://localhost/myrootdir/user/10
(POST) http://localhost/myrootdir/user/10/Smith/John/true
(DELETE) http://localhost/myroot/user/10
(POST) http://localhost/myroot/user_status/10/false

Thanks to your examples, I learned how to turn these URIs into classic URLs.
I also dicovered the $_SERVER['REQUEST_METHOD'] instruction, in order to know if the first http://localhost/myhome/user/10/Smith/John/false is sent to create or to modify an user, or if http://localhost/myhome/user/10 is sent to display or to delete an user.
Thank you for this. My only real problem at this time is the creation of the Rest requests (PUT, GET, POST, DELETE, ...).

First, example2 (and 3) must run...

  8. Re: Wamp 2.0   Reply   Report abuse  
Picture of Diogo Souza da Silva
Diogo Souza da Silva
2009-12-01 19:19:12 - In reply to message 7 from KiosqueC
Maybe try var_dump($params[0]) or var_dump($params) to see what is happening.

In last case you can use, instead of $params, this line:

$rest->getParameter("user");

To get the user.

For your intention the UserController probrably provide better code.

There is also a code for a real application that I run:

http://github.com/diogok/ideaswallorg/tree/master/war/

The relevant part is just the index.php, controller/IdeasController.class.php and controller/UserController.class.php

It is a bit confusing some parts, and you can't really run it outside google app engine, but there is the complete code that can give a better overview.

From this plan of URLs you sent I can tell that you already "got" most of how Rest webservices are supposed to be.

The only change I see is that for POST and PUT, you don't send the data on the URL, but in the body of the request, like:

POST /myrootdir/user/10/

And in the body of the request:

name=John&last_name=Doe&status=false

It's like this when you submit a html form that use POST. You would receive them in the service like in a $_POST.

But, as you said, example2 must run, I think the lines I provide at start will do it.

  9. Re: Wamp 2.0   Reply   Report abuse  
Picture of KiosqueC
KiosqueC
2009-12-02 13:58:41 - In reply to message 8 from Diogo Souza da Silva
It's better. Here are my results with various tests in home.php:

1 - var_dump($params['user']); or var_dump($params["user"]);
==> null

2 - print_r($params);
==> Array ( [0] => stdClass Object ( [name] => New User ) )

3 - print_r($params[0]);
==> stdClass Object ( [name] => New User )

4 - print_r($rest->getParameter("user"));
==> stdClass Object ( [name] => New User )

5 - var_dump($params);
==> array
0 =>
object(stdClass)[5]
public 'name' => string 'New User' (length=8)

6 - var_dump($params[0]);
==> object(stdClass)[5]
public 'name' => string 'New User' (length=8)

7 - var_dump($rest->getParameter("user"));
==> object(stdClass)[5]
public 'name' => string 'New User' (length=8)

8 - foreach($params as $cle=>$valeur) echo ($cle." = ".$valeur);
==> 0 =

9 - foreach($params[0] as $cle=>$valeur) echo ($cle." = ".$valeur);
==> name = New User

10 - foreach($rest->getParameter("user") as $cle=>$valeur) echo ($cle." = ".$valeur);
==> name = New User

So, in index.php, that's the result for:
// Maps the urls and methods
$rest->addMap("GET", "/?","HomeController");

With this home.php (generic view):
----------------------------------

<h1>Homepage</h1>
<?php
var_dump($params[0]);
?>

my browser displays:
--------------------

Homepage

object(stdClass)[5]
public 'name' => string 'New User' (length=8)

... and nothing else.

Now, what about this?
// We can use fluent interface
$rest->addMap("GET", "/user", "UserController")->addMap("GET", "/user/[0-9]+", "UserController::profile");

I suppose that [0-9]+ is for the ID and not for the user name? A flag shown me that the profile functon is called when I enter this URL:
http://localhost/restserver/exemple2/user/123
(123 is read as an id, but no user is found).

However, $rest->addMap("GET","/?","HomeController"); in index.php should create a new user ("New User"), but doesn't do it.
Probably, home.php must be completed, in order to add "New User" in a database or an XML file, and UserController has to get "New User" in this database or this XML file.


  10. Re: Wamp 2.0   Reply   Report abuse  
Picture of Diogo Souza da Silva
Diogo Souza da Silva
2009-12-03 00:57:17 - In reply to message 9 from KiosqueC
This is a basic example, the main is the .htaccess trick, so that is as far as home.php go, now that you have the user object you can display it as you wish.

Now the next one, it is all as it was supposed actually, if you look at UserController profile function , there is no user (so no id is found) because there is no real database or xml, so it always will return 404.

By the way, to turn this "id" into a "name", change [0-9] to [a-zA-Z], for a letter only username.

The add of a new user should be done in $rest->addMap("POST","/user","UserController::insert"), and so in the method insert of the UserController. But again, no real database code is there. And it is a POST request.