craftcms / element-api

Create a JSON API/Feed for your elements in Craft.
MIT License
498 stars 57 forks source link

how to load custom transformer in craft 3 #64

Closed keithmancuso closed 6 years ago

keithmancuso commented 6 years ago

I see in the docs how to write one, and how to use one in the config file but im a little confused on how to load the transformer class into the element api's config file?

currently i have it working by adding this to the top of the element-api.php config file, is this the right way?

require Craft::$app->path->getConfigPath().'/transformers/default.php';
brandonkelly commented 6 years ago

You could either do that, define the class right in your config/element-api.php file, or create a src/ directory at the root of your project and put it in there with some project-specific namespace (e.g. myproject), and configure your project’s composer.json to autoload classes within that namespace using the autoload config setting.