Download the PHP package php-mvc-project/php-mvc without Composer

On this page you can find all versions of the php package php-mvc-project/php-mvc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-mvc

PHP MVC

PHP from Packagist GitHub release Packagist

The best implementation of the Model-View-Controller architectural pattern in PHP!

Features

Requirements

Installation

Server Configuration

The server must send the entire request to the ./index.php file.

Apache

nginx

Basic Usage

Create the following structure in the project root directory:

./index.php

IMPORTANT: You must use namespaces in your application. Be sure to specify the root namespace of your application using the AppBuilder::useNamespace(string) function.

./controllers/HomeController.php

IMPORTANT: The names of all controller classes must end with the Controller suffix. For example: HomeController, AccountController, TestController etc.

Structure

Your projects must implements the strict structure:

And adhere to the following rules:

  1. Folder names must be in lowercase.

  2. The views filenames must be in lowercase.

  3. The file names of the controllers must be specified in the camel style, with a capital letter. The names must end with the Controller suffix. For example: HomeController.php.

Models

The model is just classes. You can create any classes, with any structure.

It is recommended to adhere to the rule: the simpler, the better.

Using the static class Model, you can add metadata to a model in the constructor of the controller.

Views

The views files contain markup. Markup can be complete or partial.

Using the PhpMvc\Html class, you can create markup for HTML elements or output some views within other views.

For example:

Use the helper class PhpMvc\View to customize the behavior of the view:

Controllers

The controller classes names must match the controllers filenames. For example: file name is TestController.php, class name is TestController.

Each controller class must inherit from the PhpMvc\Controller class.

The controller classes must contain action methods.

The action names must match filenames of views. For example: view file is index.php, action name is index.

All methods of actions must have the modifier public.

The names of the action methods must not start with the underscore (_).

Each action can take any number of parameters.

The parameters can be received from the query string, or from the POST data.

The following example shows the output of parameters retrieved from the query string:

Below is an example of obtaining a model sent by the POST method:

Methods of action can return different results, in addition to views.

You can use the ready-made methods of the base class of the controller to output the data in the required format:

Instead of the presented methods, you can independently create instances of the desired results and return them:

All result classes implement the ActionResult interface. You can create your own result classes!

Filters

Filters allow you to add handlers before and after the action. And also handle errors of the action execution.

The filters must be in the ./Filters folder.

Each filter must be inherited from the PhpMvc\ActionFilter class.

Filters can be global, or work at the level of an individual controller, or action.

Filters for specific controller or action can be set in the controller's constructor:

./controllers/TestController.php

./filters/TestFilter.php

./filters/ExceptionToJson.php

Routing

You can set routing rules using the AppBuilder::routes() function, which expects the function as a parameter. When called, an instance of RouteProvider will be passed to the function.

The add(string $name, string $template[, array $defaults = null[, array $constraints = null]]) method allows you to add a routing rule.

The ignore(string $template[, $constraints = null]) method allows you to add an ignore rule.

The names of the routing rules must be unique.

The higher the rule in the list (the earlier the rule was added), the higher the priority in the search for a match.

In templates you can use any valid characters in the URL.

Use curly braces to denote the elements of the route.

Each element must contain a name.

A name can point to a controller, action, or any parameter expected by the action method.

For example, template is: {controller}/{action}/{yyyy}-{mm}-{dd}.

Action is:

After the element name, you can specify a default value in the template. The default value is specified using the equals sign.

For example: {controller=home}/{action=index} - default controller is HomeController, default action is index(). The default values will be used if the address does not have values for the specified path elements. Simply put, for requests /home/index, /home and / will produce the same result with this template.

If the path element is optional, then the question (?) symbol is followed by the name. For example: {controller=home}/{action=index}/{id?} - id is optional, {controller=home}/{action=index}/{id} - id is required.

Route providers must implement the RouteProvider interface. The default is DefaultRouteProvider. If necessary, you can create your own route provider. Use the AppBuilder::useRouter(RouteProvider $routeProvider) method to change the route provider.

Caching

To use caching, you must call the AppBuilder::useCache(CacheProvider $cacheProvider) method, which should be passed to the cache provider instance.

The cache provider must implement the CacheProvider interface.

You can use the ready-made FileCacheProvider, which performs caching in the file system.

You can access the cache via an instance of HttpContextBase.

For example, in the controller:

In the view:

For output caching, you can use the static OutputCache class.

Caching rules can be specified for both the controller and for an each action.

Cache rules should be specified in the constructor of the controller.

License

The MIT License (MIT)

Copyright © 2018, @meet-aleksey


All versions of php-mvc with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package php-mvc-project/php-mvc contains the following files

Loading the files please wait ....