2

First of all I hope you forgive my bad English,I'm trying to create a datastore in GeoServer using PHP so can you please give me an example that can guide me to achieve it.

The code I have is:

$app->match('/send', function() use ($app){
$curl = new Curl();
$encoder = [new XmlEncoder('datastore'), new \Symfony\Component\Serializer\Encoder\JsonEncoder()];
$normalizer = [new \Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer()];
$serializer = new \Symfony\Component\Serializer\Serializer($normalizer, $encoder);
$service = "http://localhost:8080/geoserver/"; // replace with your URL
$reqt = "rest/workspaces.xml"; // to add a new workspace
$url = $service . $reqt;
$curl->setOpt(CURLOPT_POST, True);
$curl->setBasicAuthentication('admin', 'geoserver');
$json = json_encode($curl->get($url));
$data = json_decode($json, TRUE);
$request = Request::createFromGlobals();
if($request->isMethod('POST')){
 $params = [
 'name' => $request->get('name'),
 'type' => 'GeoTIFF',
 'description' => $request->get('description'),
 'url' => __DIR__ . '/' .$file->getClientOriginalName(),
 'enabled' => 'on' == $request->get('enabled') ? 'true' : 'false',
 ];
 $curl->setOpt(CURLOPT_UPLOAD, TRUE);
 $json = $app['serializer']->serialize($data, 'json'); 
 $curl->setHeader("Content-type"," application/json");
 $target = "http://localhost:8080/geoserver/rest/workspaces/{$request->get('workspace')}/datastores";
 return new Response($curl->post($target, $json));
}
return $app['twig']->render('form.html.twig', ['data' => array_shift($data)]);
})->bind('send');
nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Nov 8, 2014 at 20:50

1 Answer 1

1

There are some PHP REST samples already mentioned at this other answer but links are dead.

You can also use the samples at IBM DeveloperWorks "Get started with GeoServer and its REST API" (to download and in the post).

answered Nov 8, 2014 at 22:42
1
  • Thanks for your help :) i will use the php wrapper and add some things on it maybe Commented Nov 8, 2014 at 23:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.