Back to ApiRouter class

Method createCRUDRoutes

public void
createCRUDRoutes
(mixed $baseName, mixed $controller, mixed $defaults = [], mixed $publicGets = false)
Creates routes map for CRUD
Parameters
  • string $baseName The base name of the component.
  • string $controller The name of the controller that contains CRUD functions.
  • array $defaults An array of default values that are used when the URL is matched.
  • bool $publicGets Allow the public to make GET requests.
Returns
  • void
Since
  • 4.0.0
Class: ApiRouter
Project: Joomla

Method createCRUDRoutes - Source code

/**
 * Creates routes map for CRUD
 *
 * @param   string  $baseName    The base name of the component.
 * @param   string  $controller  The name of the controller that contains CRUD functions.
 * @param   array   $defaults    An array of default values that are used when the URL is matched.
 * @param   bool    $publicGets  Allow the public to make GET requests.
 *
 * @return  void
 *
 * @since   4.0.0
 */
public function createCRUDRoutes($baseName, $controller, $defaults = [], $publicGets = false)
{
    $getDefaults = array_merge(['public' => $publicGets], $defaults);
    $routes = [new Route(['GET'], $baseName, $controller . '.displayList', [], $getDefaults), new Route(['GET'], $baseName . '/:id', $controller . '.displayItem', ['id' => '(\\d+)'], $getDefaults), new Route(['POST'], $baseName, $controller . '.add', [], $defaults), new Route(['PATCH'], $baseName . '/:id', $controller . '.edit', ['id' => '(\\d+)'], $defaults), new Route(['DELETE'], $baseName . '/:id', $controller . '.delete', ['id' => '(\\d+)'], $defaults)];
    $this->addRoutes($routes);
}