How and When to Use PSR-4 Autoloading in Your Craft Plugins

If you’re developing a reasonably sophisticated Craft plugin, chances are you’ll have a lot of class files which don’t really fit into the “standard” Craft plugin sub-directories of models, records, and so forth.

In this situation, you need a way to easily loading your “non-standard” classes as-and-when they’re required. PSR-4 autoloading is the perfect solution to this problem, and by the end of this article you’ll know everything you need in order to use it in your plugins.

Introducing Glossary for Craft

Today, we’re proud to release Glossary, a new Craft plugin.

Glossary makes it easy to implement a list of entries, grouped by X and ordered by Y. For example:

  • A list of staff members, grouped by the first letter of their surname, and ordered by forename;
  • A list of countries, grouped by continent, and ordered by population;
  • A list of recipes, grouped by cooking method, and ordered by cooking time.

It’s possible to achieve all of the above using Twig, but the result is messy and difficult to test.

Glossary keeps your templates neat, and has a suite of unit tests to ensure everything runs smoothly.

The Definitive Guide to Validation in Craft, Part 2: Attributetypes

The first instalment of this series provided a high-level overview of validation in Craft. We covered what happens behind the scenes when Craft validates your model, which model validation methods are available (and what each one does), and how to define your model attributes.

This instalment is all about Craft’s AttributeTypes: what they are, what they do, and which ones are available.

The Definitive Guide to Validation in Craft, Part 1: Foundations

If you’re working on a Craft plugin that accepts user input, chances are you’ll want to validate that data.

Thanks to its Yii underpinnings, Craft includes lots of powerful validation features as standard. Unfortunately, the Craft documentation is, at time of writing, somewhat lacking in this area, and the Yii documentation isn’t directly applicable.

This series of articles aims to address this problem, by providing a complete guide to validation in Craft, all the way from the high-level concepts, right down to the nuts and bolts of implementation.