MVC Rest Controller

Zemit MVC Rest Controller aims to simplify the process in a straightforward way while keeping the security, flexibility as well as Phalcon's native features.

Default Actions

Good to know: The controller usually refer to the associated model name. You can map the controller to another model by overriding the method getModelClassName() to fit your needs.

By default, the default action (indexAction) will analyse the request and forward it to the respective action as shown below:

Optional path: The id parameter in the path is always optional and can be provided as a GET, a POST data or in a raw JSON BODY. If no id is passed, the system will act as if you want to create a new entry.

More actions are available using their respective path. See the list below:

Default Responses

Creating your own Rest Controller

Simply create a controller and then extend from the Zemit\Mvc\Controller\Rest class. In this example below, UserController will automatically get the User model from the defined namespaces within Module.php.

// ./app/Modules/Api/Controllers/UserController.php
namespace App\Modules\Api\Controllers;

class UserController extends Zemit\Mvc\Controller\Rest
{
    // ...
}

Forcing a custom model

// ./app/Modules/Api/Controllers/UserController.php
namespace App\Modules\Api\Controllers;

class UserController extends Zemit\Mvc\Controller\Rest
{
    public function getModelClassName()
    {
        return App\Common\Models\User::class
    }
}

Last updated