1. Home
  2. Docs
  3. Simpods MVC
  4. Tutorials
  5. Models
  6. How To Create An Admin Model

How To Create An Admin Model

Location

Admin models are located in the /mvc/admin/models/ directory and must extend the MVC_Admin_General class. The class name should be prefixed with MVC_Admin_ and the filename should be the class name in lowercase with an extension of .class.php. For example, with a portfolio model, the class name could be MVC_Admin_Portfolio with a filename of mvc-admin-portfolio.class.php. If desired, models can be organised into sub-directories.

Required Methods

All admin models are recommended to implement the following public methods;

  • actions: Registers all action hooks.

  • filters: Registers all filter hooks

  • interface: Outputs the content of the admin page

Whilst not required it is also recommended to implement menu_link_fn to add an item to the Simpods settings menu.

Required Properties

All admin models must define the following public properties;

  • const PAGE_SLUG: String, the page slug which will appear in the URL

  • const DB_TABLE: String, the table name to be created to hold the settings

  • const PAGE_CAP: String, the capabilities a user has to have to view/edit the settings

  • const PAGE_ICON: String, the page icon, use dashicon e.g. ‘dashicons-desktop’.

  • const INIT_CLASS: Boolean, initialise the class when Simpods is loaded if is true.

Example File

In the Simpods Basic theme, a minimal template is located in the /mvc/admin/models/mvc-admin-sample.class.php file. Note that this file will be loaded; to avoid errors remember to name your model class before saving a new file.