Reading data from your Web Service – adding a GET endpoint to your component
Let’s start creating ProjectsController
to get the list of projects in our database. Please create the src/component/api/components/com_spm/src/Controller/ProjectsController.php
file with the following content:
<?php namespace Piedpiper\Component\Spm\Api\Controller; use Joomla\CMS\MVC\Controller\ApiController; class ProjectsController extends ApiController { protected $contentType = 'Projects'; protected $default_view = 'Projects'; }
In this code, we indicate the namespace for our Web Service controller, and we create the class that handles its logic. We extend Joomla’s ApiController
class, which will save us lots of coding as this class already provides the basic methods such as displayList()
and add()
.
Inside the class, we need to define the $contentType
and $default_view
variables with the name of our data...