Download the PHP package richie314/simple-mvc without Composer
On this page you can find all versions of the php package richie314/simple-mvc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package simple-mvc
A minimal Model-View-Control library for PHP
A small PHP MVC library with explicit routes, controllers, PHP views, action attributes, and utility helpers.
Webserver setup
Installation
The library requires PHP 8.3 or newer, including sensitive-parameter redaction for password arguments. The optional database integration uses mysqli; MIME detection uses fileinfo.
Quick start
Create this directory structure:
Visit /?name=Ada for HTML or /hello?first-name=Ada for JSON.
GET query strings and POST form fields become named action arguments; hyphens in field names become underscores. Match action parameter names to submitted fields and provide defaults for optional values. Other request methods do not automatically bind bodies or query strings. Actions must return a StatusCode or a supported integer status.
AddController() registers public methods except names starting with _ or #, plus the base route mapped to index. Keep helpers protected or private. To expose only specific actions, register explicit routes instead:
For installation under /myapp, pass pathPrefix: '/myapp' to Router and keep route names relative to that prefix (for example /welcome). $P is available to layouts and views for generating links. Routes use exact paths; trailing slashes are significant.
Controller responses
These calls belong inside controller actions:
JsonWithOptions() and RedirectWithStatus() are optional helpers; existing Json() and Redirect() signatures remain unchanged. Redirect() retains its legacy behavior: it returns MovedPermanently (301), while PHP normally sends 302 for the Location header. Use RedirectWithStatus() when the returned and emitted status must agree.
JSON encoding failures now throw JsonException, which dispatch handles as a server error when headers have not been sent. Successful content and view responses explicitly set their status, including 200.
Views resolve beneath Views/, then Views/Shared/, with .php, .html, and .htm extensions tried for names without a dot. Render() accepts the existing cutomLayout named parameter (spelling preserved) for an alternative layout path. View data and default variables are available in both layout and body. Default variables take precedence over action data; built-in variables $title, $status_code, $user, $P, and $RenderBody take precedence over both. Internal rendering variables are reserved. Escape untrusted output with htmlspecialchars().
Provide Views/Shared/Error.php to customize errors using $main_banner (and $exception for server errors). Without it, error helpers return plain text with the appropriate status. Exceptions after headers are sent are rethrown. Keep exception details out of public error templates and configure production error handling appropriately.
Authentication and database integration
Load your application user and connection before dispatch:
Protect an action with the built-in attribute:
Use requireAdmin: true to additionally require $user->Admin. Missing users are redirected to login and the original request is stored in the Redirect cookie. Authentication enforcement terminates the request. Your app supplies login and user persistence.
Utilities
SetWithOptions() and DeleteWithOptions() preserve existing cookie method signatures, including subclass overrides. Cookie security options are opt-in: existing calls retain secure: false, httpOnly: true, and no SameSite setting. Cookies must be written before response output. Cookie reads reflect the incoming request, not cookies just written to response headers.
Security::GetIpAddress() retains its existing proxy-header precedence. Enable allowCloudlfare: true only behind a trusted Cloudflare proxy. Forwarded headers must be sanitized by your infrastructure before using these addresses for access control.
Webserver configuration
Apache
Enable mod_rewrite and allow overrides for the application directory. Place this .htaccess beside index.php:
Expose only the front controller and intended public assets; deny direct access to application code, views, vendor files, and configuration in your server configuration.
Nginx
In this example the nginx server listens on port 8080 and redirectes all the traffic to index.php, except for the Public folder, where is assumed there are public static files that will be served without redirecting the request to the index.php file first.
In the configuration below, php is accessed via a unix socket.