I am new to Web service and i like to make a web service in Zend Framework 2 using AbstractRestfulController.. Can any one give me a simple example. May be with a single function.
Thanks.
I am new to Web service and i like to make a web service in Zend Framework 2 using AbstractRestfulController.. Can any one give me a simple example. May be with a single function.
Thanks.
In your config.module.php
'controllers' => array(
'invokables' => array(
'My\Controller\ObjectController' => 'My\Controller\ObjectController'
)
)
In your router
'object' => array(
'type' => 'segment',
'options' => array(
'route' => '/objects[/:object_id]',
'constraints' => array(
'object_id' => '[0-9]*'
),
'defaults' => array(
'controller' => 'My\Controller\ObjectController'
)
)
),
Your controller
<?php
namespace My\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
class ObjectController extends AbstractRestfulController {
public function get($id)
{
return new JsonModel( ... add Json representation of object with $id ... );
}
public function getList()
{
return new JsonModel( ... add Json representation of object collection ... );
}
... add other methods that are needed ...
}
That is basically it