PHPackages                             shaggy8871/yurly - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. shaggy8871/yurly

ActiveLibrary[Framework](/categories/framework)

shaggy8871/yurly
================

Yurly is a lightweight MVC routing library for PHP 7

2.1.8(5y ago)42352MITPHPPHP &gt;=7.2.0CI failing

Since Jun 27Pushed 5y ago1 watchersCompare

[ Source](https://github.com/shaggy8871/yurly)[ Packagist](https://packagist.org/packages/shaggy8871/yurly)[ RSS](/packages/shaggy8871-yurly/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (4)Versions (18)Used By (0)

Yurly
=====

[](#yurly)

[![Build Status](https://camo.githubusercontent.com/de5036c1725844022dea60608bc590865b988299994ad39fd0d26544ec838960/68747470733a2f2f7472617669732d63692e6f72672f736861676779383837312f7975726c792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/shaggy8871/yurly)

Yurly is a lightweight web MVC routing library for PHP 7. It's easy to get started, requires almost zero configuration, and can run within existing projects without a major rewrite.

It also supports a multi-site implementation right out of the box.

Table of Contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Basic Routing](#basic-routing)
3. [Route Parameters](#route-parameters)
4. [Accepting Multiple Request Types](#accepting-multiple-request-types)
5. [Middleware](#middleware)
6. [Custom Request/Response Classes](#custom-requestresponse-classes)
7. [Dependency Injected Parameters](#dependency-injected-parameters)
8. [Custom Route Resolvers](#custom-route-resolvers)
9. [Multi-site Setup](#multi-site-setup)
10. [Using `ymake` Helper](#using-ymake-helper)
11. [Unit Testing](#unit-testing)

Installation:
-------------

[](#installation)

In composer.json:

```
{
    "require": {
        "shaggy8871/yurly": "^2.0"
    },
    "require-dev": {
        "phpunit/phpunit": "^8"
    },
    "autoload": {
        "psr-4": {
            "Myapp\\": "./src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "./tests/"
        }
    }
}

```

Replace `Myapp` with the name of your project.

Then run:

```
composer install

```

### Create your project

[](#create-your-project)

Once composer dependencies are installed, run the following to create a basic project file structure, along with your first set of controllers and tests:

```
vendor/bin/ymake project
```

If all works as planned, you should see output as follows:

```
Creating project structure:
  ✅  Created ./src
  ✅  Created ./src/Controllers
  ✅  Created ./src/Models
  ✅  Created ./src/Views
  ✅  Created ./src/Views/cache
  ✅  Created ./src/Views/base.html.twig
  ✅  Created ./tests
  ✅  Created ./tests/Bootstrap.php

Creating Index controller:
  ✅  Created ./src/Controllers/Index.php
  ✅  Created ./src/Models/Index.php
  ✅  Created ./src/Views/Index
  ✅  Created ./src/Views/Index/default.html.twig

Creating test Index controller:
  ✅  Created ./tests/Controllers/IndexTest.php

Creating document root:
  ✅  Created public
  ✅  Created public/index.php

```

To test the website, run the following:

```
php -S localhost:8000 -t public/

```

Then open  in your browser.

To run unit tests:

```
vendor/bin/phpunit

```

Basic Routing
-------------

[](#basic-routing)

By default, routes are determined based on the controller class name and method name.

URLRoutes ToNotes`/``Index/routeDefault``/about``About/routeDefault` or `Index/routeAbout`Yurly will try both in order`/about/our-story``About/routeOur_Story`"-" is auto-converted to "\_"Controllers must extend the `Yurly\Core\Controller` class, and must contain at least one method name prefixed with the word `route`.

> `Request` and `Response` classes can be injected into any route method. The first `Response` class found will be used to render any value returned from the `route*` method.

Example src/Controllers/Index.php file:

```
