typerocket icon indicating copy to clipboard operation
typerocket copied to clipboard

Unable to set custom handler for post CPT

Open gogolander opened this issue 3 years ago • 0 comments

Hi Kevin,

I've got a CPT called 'car' that has to interoperate with a external service. So I:

  1. asked galaxy to create the model and the controller with php galaxy make:model -c post Car
  2. decleared the CPT in my functions.php:
    ->setHandler(\App\Controllers\CarController::class);

This is the Car.php:

<?php
namespace App\Models;

use TypeRocket\Models\WPPost;

class Car extends WPPost
{
    public const POST_TYPE = 'car';
}

and this the CarController.php:

<?php
namespace App\Controllers;

use App\Models\Car;
use TypeRocket\Controllers\WPPostController;

use TypeRocket\Http\Request;
use TypeRocket\Http\Response;
use TypeRocket\Models\AuthUser;

class CarController extends WPPostController
{
    protected $modelClass = Car::class;

    public function create(Request $request, Response $response, AuthUser $user) {
        // Just to let me know that this has been called
        die('called');
    }

    public function onActionSave($type, Car $car, Request $request) {
        // Just to let me know that this has been called
        die('action');
    }
}

All seems good and I think typerocket should do what I need here but the fact is that my methods are never actually called. Is this scenario supported by typerocket? Am I missing some steps?

Thanks

Edit: I'm running:

  • WP 6.0
  • PHP 8.1
  • TypeRocket v5 installed in mu-plugins

gogolander avatar Jun 17 '22 13:06 gogolander