Download the PHP package media-store-net/wp-mvc-core without Composer
On this page you can find all versions of the php package media-store-net/wp-mvc-core. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download media-store-net/wp-mvc-core
More information about media-store-net/wp-mvc-core
Files in media-store-net/wp-mvc-core
Package wp-mvc-core
Short Description A small MVC framework for Wordpress plugins and themes.
License MIT
Informations about the package wp-mvc-core
WP MVC Core (For Wordpress plugins and themes)
This is a forked version of amostajo/[email protected]
Lightweight MVC is a small framework that adds Models, Views and Controllers to your custom Wordpress plugin or theme.
Lightweight MVC utilices existing Wordpress functionality preventing from overloading the already heavy loaded Wordpress core.
This framework was inspired by Laravel to add the MVC design pattern to Wordpress development in an efficient, elegant and optimized way.
- Requirements
- Installation
- Configuration
- Usage
- Models
- Aliases
- Types
- Views
- Controllers
- Engine
- Helpers
- Models
- Coding Guidelines
- License
Requirements
- PHP >= 7.4
Installation
Add
to your composer.json. Then run composer install
or composer update
.
NOTE If you are not using composer, you can download the ZIP but will need to include the files manually since not autoload will be generated.
Configuration
Your project needs to store somewhere your Models
, Views
and Controllers
, and Lightweight MVC must know where.
Create these as folders, like this:
Then in your functions.php
or plugins.php
file set these at the very beginnning, like:
Usage
Models
In Lightweight MVC, a Model
at the end is just a type of Wordpress post. Store your models at the models
folder.
Here is model example:
With just that, you will be able to do this:
Aliases
The model will let you add aliases to post attributes, meta values and event custom functions.
When adding aliases to properties you can do things like this:
You can extend the attributes of a post with the meta table, the model does this seamlessly when adding aliases with meta_
prefix:
Usage:
Sometimes you might need to add some logic to your attributes, you can accomplish this by adding an alias for a function using the func_
prefix:
Usage:
Aliases fields are included when casting the model to arrays, json or string.
Types
As mentioned before, a model is a post type. Once a post type has been registered by you plugin or theme, you can create a model for it.
In the following example a new post type books
has been created to handle book records:
With just that, books can be used like this:
Views
This is the templating mini-engine of Lightweight MVC.
Views are PHP files whose content is HTML most of the time. PHP tags should only be used to echo values from variables passed by.
Here an example of a view that displays a book object from the example above:
NOTE: There is no PHP logic in the view, just pure HTML, perfect for the designer to handle. Logic is placed in the controller.
You can place your views as please within the views
folder. In example, let's assuming that the view file from above is
named profile.php
, you can place it in a path like this:
The key locator for this view within the engine will be:
books.profile
NOTE: If this view is located inside a plugin, you can add the same hirachy in any theme to customize the view with the theme's styles. Lightweight MVC will give priority to the view located in the theme.
Something like this:
Controllers
Controllers are used to create handle any business logic and algorithms.
In the following example, we will use a controller to display the book profile.
Engine
Once you have everything in order, you can use the framework as following (using the same book example):
Helpers
This package comes with a request class helper, to retrieve values from GET, POST or WORDPRESS' query_vars:
Third value will clear the source value, great to prevent loop wholes with NONCE:
Coding Guidelines
The coding is a mix between PSR-2 and Wordpress PHP guidelines.
License
WP MVC Core is free software distributed under the terms of the MIT license.