DESCRIPTION

This controller contains basic route handlers for displaying content configured in Yancy collections. These route handlers reduce the amount of code you need to write to display or modify your content.

Route handlers use the Mojolicious stash for configuration. These values can be set at route creation, or by an under route handler.

This route creates a new item or updates an existing item in a collection. If the user is making a GET request, they will simply be shown the template. If the user is making a POST or PUT request, the form parameters will be read, the data will be validated against the collection configuration, and the user will either be shown the form again with the result of the form submission (success or failure) or the user will be forwarded to another place.

This method uses the following stash values for configuration:

collection

The collection to use. Required.

id

The ID of the item from the collection. Optional: If not specified, a new item will be created. Usually part of the route path as a placeholder.

Restrict this route to only setting the given properties. An array reference of properties to allow. Trying to set additional properties will result in an error.

NOTE: Unless restricted to certain properties using this configuration, this method accepts all valid data configured for the collection. The data being submitted can be more than just the fields you make available in the form. If you do not want certain data to be written through this form, you can prevent it by using this.

The following stash values are set by this method:

item

The item that is being edited, if the id is given. Otherwise, the item that was created.

delete

This route deletes an item from a collection. If the user is making a GET request, they will simply be shown the template (which can be used to confirm the delete). If the user is making a POST or DELETE request, the item will be deleted and the user will either be shown the form again with the result of the form submission (success or failure) or the user will be forwarded to another place.

This method uses the following stash values for configuration:

collection

The collection to use. Required.

id

The ID of the item from the collection. Required. Usually part of the route path as a placeholder.

EXTENDING

Here are some tips for inheriting from this controller to add functionality.

set

When setting field values to add to the updated/created item, use $c->req->param not $c->param. The underlying code uses $c->req->param to get all of the params, which will not be updated if you use $c->param.

DIAGNOSTICS

Page not found

If you get a 404 Not Found response or Mojolicious's "Page not found... yet!" page, it could be from one of a few reasons:

No route with the given path was found

Check to make sure that your routes match the URL.

Configured template not found

Make sure the template is configured and named correctly and the correct format and renderer are being used.

The Mojolicious debug log will have more information. Make sure you are logging at debug level by running in development mode (the default), or setting the MOJO_LOG_LEVEL environment variable to debug. See MODE in the Mojolicious tutorial for more information.

As a valued partner and proud supporter of MetaCPAN, StickerYou is
happy to offer a 10% discount on all Custom Stickers,
Business Labels, Roll Labels,
Vinyl Lettering or Custom Decals. StickerYou.com
is your one-stop shop to make your business stick.
Use code METACPAN10 at checkout to apply your discount.