Download the PHP package paigejulianne/nanomvc without Composer

On this page you can find all versions of the php package paigejulianne/nanomvc. 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 nanomvc

NanoMVC

A lightweight MVC framework for PHP 8.0+ with support for Blade, Smarty, and Twig templates.

Version 1.0.1 | License: GPL-3.0

by Paige Julianne Sullivan paigejulianne.com | GitHub


Features


Prerequisites


Installation

Via Composer (Recommended)

Manual Installation

Download NanoMVC.php and include it in your project:


Examples

NanoMVC includes four example applications demonstrating each template engine:

Example Template Engine Directory
PHP (Native) Native PHP example/
Blade Laravel Blade example-blade/
Smarty Smarty example-smarty/
Twig Twig example-twig/

Running the Examples

  1. Install dependencies:

  2. For Blade example, also install:

  3. For Smarty example, also install:

  4. For Twig example, also install:

  5. Set file permissions:

  6. Access in your browser:
    • PHP: http://localhost/path/to/nanomvc/example/
    • Blade: http://localhost/path/to/nanomvc/example-blade/
    • Smarty: http://localhost/path/to/nanomvc/example-smarty/
    • Twig: http://localhost/path/to/nanomvc/example-twig/

Note: Ensure Apache mod_rewrite is enabled and AllowOverride All is set for your directory. See Apache Configuration for details.


Quick Start

1. Create Your Entry Point

Create index.php:

2. Create Configuration (Optional)

Create .config:

3. Define Routes

Create routes.php:

4. Create a Controller

Create controllers/HomeController.php:

5. Create a View

Create views/home.php:


Configuration

Using a .config File

Programmatic Configuration


Routing

Basic Routes

Route Parameters

Route Groups

Nested Groups

Route Handlers

Routes can use closures or controller methods:

Middleware

Custom Error Handlers

Route Caching (Production)

For large applications, cache compiled routes for faster startup:

Route Statistics

Monitor route performance:


Controllers

Creating Controllers

Extend the base Controller class:

Response Methods

Validation

Available Rules:


Request Object

Getting Input

Route Parameters

Request Info


Response Object

Creating Responses

Modifying Responses

Response Compression

Responses are automatically gzip-compressed when the client supports it:


Views

Template Engines

PHP (Native) - Default, no dependencies:

Blade - Requires jenssegers/blade:

Smarty - Requires smarty/smarty:

Twig - Requires twig/twig:

Rendering Views

Shared Data

Template Examples

PHP Template (views/users/index.php):

Blade Template (views/users/index.blade.php):

Smarty Template (views/users/index.tpl):

Twig Template (views/users/index.twig):


Integration with NanoORM

Creating Models

Using Models in Controllers


Session Management

Basic Usage

Flash Messages

CSRF Protection

Session Configuration

Custom Session Storage


Rate Limiting

Basic Usage

Throttle Middleware


Security Middleware

CSRF Middleware

CORS Middleware


Directory Structure


Apache Configuration

Basic .htaccess

Create .htaccess in your application directory:

Note: Do not use RewriteBase unless your application is installed at the web root. The above configuration works for subdirectory installations.

File Permissions

Ensure Apache can read the .htaccess file:

Enabling mod_rewrite

If mod_rewrite is not enabled, run:

Apache User Directories (~username)

If running NanoMVC in a user directory (e.g., http://localhost/~username/myapp/), you need to configure Apache to allow .htaccess overrides.

Edit /etc/apache2/mods-available/userdir.conf:

Then restart Apache:

Subdirectory Installation

NanoMVC automatically detects when installed in a subdirectory and adjusts routing accordingly. For links in your views, calculate the base URL:


Nginx Configuration


Testing

Run tests with PHPUnit:


API Reference

Router

Method Description
get($path, $handler, $middleware) Register GET route
post($path, $handler, $middleware) Register POST route
put($path, $handler, $middleware) Register PUT route
patch($path, $handler, $middleware) Register PATCH route
delete($path, $handler, $middleware) Register DELETE route
any($path, $handler, $middleware) Register route for all methods
match($methods, $path, $handler, $middleware) Register route for specific methods
group($options, $callback) Create route group
dispatch($request) Dispatch request to handler
setNotFoundHandler($handler) Set 404 handler
setErrorHandler($handler) Set error handler

Controller

Method Description
view($template, $data, $status) Render view response
json($data, $status) JSON response
redirect($url, $status) Redirect response
text($content, $status) Plain text response
html($content, $status) HTML response
validate($rules) Validate request input
request() Get current request

Request

Method Description
method() Get HTTP method
path() Get request path
query($key, $default) Get query parameter
input($key, $default) Get input value
all() Get all input
only($keys) Get specific keys
except($keys) Get all except keys
has($key) Check if key exists
param($name, $default) Get route parameter
params() Get all route parameters
header($name, $default) Get header
cookie($name, $default) Get cookie
isAjax() Check if AJAX request
expectsJson() Check if expects JSON
json() Get JSON body

Response

Method Description
setContent($content) Set response body
setStatusCode($code) Set HTTP status
header($name, $value) Add header
withHeaders($headers) Add multiple headers
send() Send response
json($data, $status) Create JSON response
redirect($url, $status) Create redirect response
text($content, $status) Create text response
html($content, $status) Create HTML response

View

Method Description
configure($viewsPath, $cachePath, $engine) Configure view system
render($template, $data) Render template to string
make($template, $data, $status) Create response with view
share($key, $value) Share data with all views
engineAvailable($engine) Check if engine available

App

Method Description
run($basePath) Run the application
config($key, $default) Get config value
setConfig($key, $value) Set config value
isDebug() Check debug mode
setDebug($debug) Set debug mode
basePath($path) Get base path

Session

Method Description
start() Start the session
get($key, $default) Get session value
set($key, $value) Set session value
has($key) Check if key exists
forget($key) Remove session value
all() Get all session data
flush() Clear all session data
destroy() Destroy session completely
flash($key, $value) Flash value for next request
getFlash($key, $default) Get and remove flash value
csrfToken() Get CSRF token
verifyCsrfToken($token) Verify CSRF token
configure($config) Configure session settings
setDriver($driver) Set custom session driver
regenerate() Regenerate session ID

RateLimiter

Method Description
attempt($key, $max, $decay) Check/increment rate limit
remaining($key, $max) Get remaining attempts
availableIn($key) Seconds until limit resets
clear($key) Clear rate limit for key
hits($key) Get current hit count
setStore($store) Set storage backend

Router (Additional Methods)

Method Description
cacheRoutes($file) Cache routes to file
loadCachedRoutes($file) Load routes from cache
isRouteCached() Check if routes are cached
getStats() Get route statistics
clearMiddlewareCache() Clear middleware cache

Response (Additional Methods)

Method Description
withCompression() Enable gzip compression
withoutCompression() Disable gzip compression
configureCompression($threshold, $level) Configure compression settings

Request (Additional Methods)

Method Description
getContentStream() Get stream handle for body
readContentChunked($callback, $size) Read body in chunks
setMaxBodySize($bytes) Set max request body size
getMaxBodySize() Get max request body size

Troubleshooting

404 Errors on All Routes

  1. Check mod_rewrite is enabled:

  2. Check AllowOverride is set: Ensure your Apache configuration allows .htaccess files. See Apache User Directories above.

  3. Check .htaccess permissions:

403 Forbidden / "Unable to read htaccess file"

This is a file permissions issue. Apache cannot read the .htaccess file:

500 Internal Server Error

  1. Check PHP error logs: Usually at /var/log/apache2/error.log

  2. Enable debug mode: Set debug=true in your .config file

  3. Check .htaccess syntax: Some directives (like Options) may not be allowed in your Apache configuration

Views Not Loading

Ensure view paths in .config are relative to your application directory:

NanoMVC automatically resolves relative paths against the application's base directory.

Links Not Working in Subdirectory

When installed in a subdirectory, use $baseUrl for all links:


Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

License

NanoMVC is released under the GPL-3.0-or-later license.

Copyright 2024-present Paige Julianne Sullivan


All versions of nanomvc with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
paigejulianne/nanoorm Version ^1.0 || ^2.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 paigejulianne/nanomvc contains the following files

Loading the files please wait ...