- Home
- Skills
- Proxiblue
- Claude Skills
- Create Frontend Controller
create-frontend-controller_skill
7
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill proxiblue/claude-skills --skill create-frontend-controller- SKILL.md11.8 KB
Overview
This skill creates a frontend controller action for Magento 2 storefronts. It explains routing, controller class patterns, and returning Page, JSON, Redirect, or Raw results so you can build custom pages, AJAX endpoints, form handlers, or API-like endpoints for JavaScript.
How this skill works
It adds a route in etc/frontend/routes.xml and a controller class under Controller/{ControllerName}/{ActionName}. The controller implements HttpGetActionInterface and/or HttpPostActionInterface, injects dependencies via constructor, and returns a Result object created by a result factory (PageFactory, JsonFactory, RedirectFactory, or RawFactory). The skill includes common patterns for collection-based AJAX, form submission handling, authentication checks, and layout/template wiring for full-page responses.
When to use it
- Create custom AJAX endpoints consumed by frontend JavaScript
- Build a storefront page or custom action accessible to customers
- Handle form submissions with CSRF and redirect flows
- Expose simple API-like endpoints for Alpine.js or fetch() calls
- Return JSON, full HTML pages, or redirects from the storefront controller
Best practices
- Implement HttpGetActionInterface and/or HttpPostActionInterface according to allowed HTTP methods
- Declare strict types (declare(strict_types=1)) at the top of controller files
- Use dependency injection; never call ObjectManager directly
- Return proper Result objects via result factories (JsonFactory, PageFactory, RedirectFactory, RawFactory)
- Validate request method and use Magento messageManager and redirects for form handlers
- Follow PSR-12, namespace-to-directory mapping, and clear caches after changes
Example use cases
- AJAX search endpoint that filters a collection and returns paginated JSON results
- Custom storefront page that renders a template via PageFactory and layout XML
- Form submission handler that checks POST, processes data, sets success/error messages, and redirects
- Redirect controller that sends users to customer/account or other routes
- Endpoint for Alpine.js using fetch() to call a JsonFactory response
FAQ
URL structure is /{frontName}/{controller}/{action} where frontName is defined in etc/frontend/routes.xml and controller/action match the Controller folder and class name.
How do I return JSON from a controller?
Inject Magento\Framework\Controller\Result\JsonFactory, create a result with create(), then setData(array) and return it.