My First Craft CMS Module

Restructuring the Module

We redo the module structure to use a src directory and make plans to add a service class.

The first thing we’ll do is restruc­ture the direc­to­ry, so we have our mod­ule source code in a src direc­to­ry. This is a com­mon pat­tern you’ll see in plu­g­ins so let’s fol­low that. This isn’t nec­es­sary — and our code will still func­tion­ing just fine with­out it — but will also be an eas­i­er tran­si­tion to devel­op­ing plu­g­ins for Craft CMS when the time comes for that.

After chang­ing the loca­tion our mod­ule class file, we need to let Com­pos­er know about that and then rebuild the autoload files.

My First Craft CMS Module is made up of the following videos: