1. Home
  2. Docs
  3. Simpods MVC
  4. Basic Components
  5. Custom Controllers

Custom Controllers

What are custom controllers?

Custom controllers allow you to add additional functionality to pages that otherwise would not accept a controller, such as some plugin pages. In figure 1, you can see some controllers we created to alter and add to the plugin used for this very documentation. These custom controllers then allow you to create a controller in your child theme and add, alter or remove any functionality you desire. You also have the opportunity here to enqueue some styles & scripts.

Custom Controllers Example

Figure 1 – An example of some custom controllers

Creating a controller

Creating a custom controller is a simple 5 step process:

  1. Type: Select between whether you want the controller to be loaded in the front end or backend. Note that this will change where the controller has to be located.
  2. URL Path: What URL do you want to load the controller? For example, if you were using The Events Calendar and wanted to load the controller for a particular event, you could enter “event/simpods-mvc-talk”. If you wanted the controller to work for any event, you could enter “event/*” which would work as a wildcard for all events.
  3. Controller Path: Where in your child theme do you want the controller to be? By default, frontend controllers go in “mvc/control” and admin controllers go in “mvc/admin/control”. This will allow you to name the file and its location within their respective controllers. For instance, for an events controller, you could enter “events/single-event.php”.
  4. Note: This section is simply so that you know what the controller is meant for so that you can remove or alter the controller you need.
  5. Create Controller: Once you click this button, you’re done! Simpods MVC will create the controller and display the information you inputted in the table below.
Create a Controller

Figure 2 – Add Controllers reference

Custom controller settings

We’ve added some options to make things a little easier for you while developing:

  1. Disable Custom Controllers: Don’t want to use custom controllers? Are your custom controllers causing you some hassle? No problem! You can go ahead and toggle this option at any time and any custom controller you created will no longer be included on page loads.
  2. Show Admin Controller Path: Want to see what controller you need for your admin page? This option allows you to choose between not showing the path, showing the path and showing the path for admins only.
  3. Show Frontend Controller Path: This option is the same as the previous one, with the exception that this will show the path for frontend pages. Simply change the option between not showing, showing for everyone and showing for admins only.

Don’t forget to click “Update Settings” before leaving the page!

Custom Controller Settings

Figure 3 – Custom Controller settings reference