3. The Sample Application

Agavi comes with a (very simple) sample application. To make it work, all you have to do is adjust samples/pub/index.php to point to agavi.php, whereever it's installed, and maybe change permissions of samples/app/cache so it's writeable by your web server or PHP. Then, fire it up in your browser and play around with it.

While not overly complex, the sample application's code should give you a basic understanding of what a software project in Agavi would look like in terms of structure.

The sample app also supports XMLRPC. It exposes a method called "getItemPrice" that can be used to retrieve the price for the products the SearchEngineSpam action knows. Use the following script to test this (needs curl and xmlrpc extensions):

<?php

header('Content-Type: text/html; charset=utf-8');

?>
<html>
  <head>
    <title>test</title>
    <meta http-equiv="Content-Type" value="text/html; charset=utf-8" />
  </head>
  <body>
    <pre>
<?php
$request = xmlrpc_encode_request('getItemPrice', array('name' => 'viagra'), array("encoding" => "utf-8", "escaping" => "markup"));

$url = "http://localhost/path/to/the/samples/pub/xmlrpc.php";

$header[] = "Content-type: text/xml; charset=utf-8";
$header[] = "Content-length: ".strlen($request);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HEADER, true);

$data = curl_exec($ch);
if(curl_errno($ch)) {
  echo curl_error($ch);
} else {
  curl_close($ch);
  echo htmlspecialchars($data);
}

?>
    </pre>
  </body>
</html>