Download the PHP package cuculcan/core without Composer
On this page you can find all versions of the php package cuculcan/core. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cuculcan/core
More information about cuculcan/core
Files in cuculcan/core
Informations about the package core
CORE
Small simple PHP MVC RESTlike framework for training purposes
installation
Navigation
Model
Controller
View
Model
Models are objects inherited from the Entity class. The entity corresponds to the row in the database table
each entry has at least an "id" field
User class example:
Entity fields can be annotated.
extra means that this property has no relation to the table column
type = json used to pack arrays in json when saving to db
default_value = used to set the default value in case the value is undefined
the constructor should be described as in the example and have at least the data parameter used to build the object after selecting from the database
Storages
For entities, storage objects are created that implement the functionality for working with the Database Repositories inherit from the MysqlStorage base class
СRUD methods for the Entity object are implemented in the base class MysqlStorage
Controllers
Controllers are designed to handle incoming requests
Any request to the site is converted using .htaccess RewriteRule
or nginx rewrite
and sent to index.php
The sequence of request processing is as follows:
Controller Inheritance Chain
AController is abstract. Invokes methods for handling addresses described in specific controllers. Should not depend on a specific project
BaseController inherits from AController and contains common methods for all user controllers. For example, initialization of a session user. Preparing data for menus and others.
MainController and other user controllers are inherited from BaseController and contain methods for processing specific url addresses. The project must have at least one controller named MainController, it is responsible for processing calls to the root of the site.
To process other requests to the site, request handlers must be described in the appropriate controllers. For example, addresses starting with:
Must be described in UserController
Routing
Each controller class must have a method implementation
Handlers of URL templates are registered inside. There are handlers for GET, POST, PUT, DELETE requests. Implemented as Methods with appropriate names
The URL template handler has the format
The implementation of the response to the request is described in the callback of this method. In the URL template, there may be a variable parameter which is written in curly brackets and may be available inside the callback
In this example, a request of the form http: //myexample.com/user/12345/get_name will be processed and 12345 will be displayed
Request parameters can be accessed through the request object and it methods
getQueryParameters() - will return an array of parameters
getQueryParameter($name, $default = null) - will return the value of the parameter or the value passed to default, if the parameter is missing
All methods described in setActions() are executed in turn and the one that matches the template is selected, if more than one method matches the pattern, an exception is thrown
In all objects of the controller, the variable model is present. It is used to transfer data to objects of the View class for later display.
The View object is called by the method $ this->showView("UserView"). The parameter is the name of the class to display.
View will be displayed with the class UserView
View
View classes inherit from the abstract class AView, used to display templates. PHP itself is used as a template engine.
MainView class example: