Open a-rbsn opened 1 year ago
I'm using the UrlHelper to generate JSON URLs for entries but the generated URL doesn't seem to work.
'projects.json' => function () { Craft::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Origin', '*'); return [ 'elementType' => Entry::class, 'criteria' => [ 'section' => 'projects', ], 'paginate' => false, 'transformer' => function (Entry $entry) { return [ 'id' => $entry->id, 'slug' => $entry->slug, 'jsonUrl' => UrlHelper::url("project/{$entry->slug}.json"), ]; }, ]; }, 'project/<entrySlug>.json' => function ($entrySlug) { Craft::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Origin', '*'); return [ 'elementType' => Entry::class, 'criteria' => [ 'section' => 'projects', 'slug' => $entrySlug, ], 'one' => true, 'transformer' => function (Entry $entry) { return [ 'id' => $entry->id, 'title' => $entry->title, 'slug' => $entry->slug, ]; }, ]; },
Can you add any detail about how it doesn't work and your particular config? Are the correct URLs being generated? Or are you getting an unexpected URL?
Description
I'm using the UrlHelper to generate JSON URLs for entries but the generated URL doesn't seem to work.
Steps to reproduce
Additional info