PHPackages                             rduuke/newbie - 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. rduuke/newbie

ActiveProject[Framework](/categories/framework)

rduuke/newbie
=============

Micro-Framework Web of PHP

v2.2.0(9y ago)019MITPHPPHP &gt;=5.5.9

Since Feb 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/RDuuke/Newbie)[ Packagist](https://packagist.org/packages/rduuke/newbie)[ Docs](https://github.com/RDuuke/Newbie)[ RSS](/packages/rduuke-newbie/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (5)Versions (7)Used By (0)

[![StyleCI](https://camo.githubusercontent.com/caf1c7b420ad595cd29a3fd9f03785e9fc28546809990656da7a3182cb78c5a2/68747470733a2f2f7374796c6563692e696f2f7265706f732f34383830363035312f736869656c64)](https://styleci.io/repos/48806051)[![Total Downloads](https://camo.githubusercontent.com/3b679ef7f4e0048e753e339bb190a4527439f60861f42bbf3239a8e8de667aae/68747470733a2f2f706f7365722e707567782e6f72672f726475756b652f6e65776269652f642f746f74616c2e737667)](https://packagist.org/packages/rduuke/newbie)[![Latest Stable Version](https://camo.githubusercontent.com/5dfd2e1f245b970fa3b001a966b361d9ff2664bd9fc02ba11caf0aa0ac3d361c/68747470733a2f2f706f7365722e707567782e6f72672f726475756b652f6e65776269652f762f737461626c652e737667)](https://packagist.org/packages/rduuke/newbie)[![Latest Unstable Version](https://camo.githubusercontent.com/0c4f2d55c61c0b50f78d7c5cdae8426992955c0960f150a24256932ab058ba18/68747470733a2f2f706f7365722e707567782e6f72672f726475756b652f6e65776269652f762f756e737461626c652e737667)](https://packagist.org/packages/rduuke/newbie)[![License](https://camo.githubusercontent.com/d6d700ff07ea0c62fd1961b65c5bb89774676613af0adf49ca6a56837bb2c6a8/68747470733a2f2f706f7365722e707567782e6f72672f726475756b652f6e65776269652f6c6963656e73652e737667)](https://packagist.org/packages/rduuke/newbie)

**Newbie**
==========

[](#newbie)

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

[](#installation)

##### Composer:

[](#composer)

```
composer create-project rduuke/newbie
```

##### Configuration Files:

[](#configuration-files)

The file `config\Config.php` data from the database is added and define the two global routes `BASE_URL` and `BASE_PUBLIC`.

```
define('BASE_URL', 'http://example.com/newbie');
define('BASE_PUBLIC', 'http://example.com/newbie/public');
```

#### Directory Structure:

[](#directory-structure)

```
/
├── bootstrap
├── config
├── public
├── resource
    ├── views
        ├── layout
├── src
    ├── Contracts
    ├── Controllers
    ├── Models
    ├── Tools
├── vendor

```

#### The HTTP Layer

[](#the-http-layer)

#### Route

[](#route)

##### Basic Routing:

[](#basic-routing)

The most basic Newbie routes simply accept a URI and a Closure, providing a very simple and expressive method of defining routes:

```
    $app->get('/', function(Request $request, Response $response){
        $response->getBody()->write("Hello Word');
        return $reponse;
    });
```

All Newbie routes are defined in your route files `src/routes.php`. Available Router Methods: The router allows you to register routes that respond to any HTTP verb:

```
    $app->get($uri, $callback);
    $app->post($uri, $callback);
    $app->put($uri, $callback);
    $app->delete($uri, $callback);
    $app->patch($uri, $callback);
    $app->options($uri, $callback);
    $app->head($uri, $callback);
```

#### Route Parameters

[](#route-parameters)

##### Required Parameters:

[](#required-parameters)

Of course, sometimes you will need to capture segments of the URI within your route. For example, you may need to capture a user's ID from the URL. You may do so by defining route parameters:

```
    $app->get('/users/{id}', function (Request $request, Response $response) {
        $id = $request->getAttribute('id');
        return $id;
    });
```

##### Optional Parameters:

[](#optional-parameters)

Occasionally you may need to specify a route parameter, but make the presence of that route parameter optional. You may do so by placing \[\]; Make sure to give the route's corresponding variable a default value:

```
     $app->get('/users[/{id}]', function (Request $request, Response $response) {
        $id = $request->getAttribute('id');
        return $id;
    });
```

##### Route Groups

[](#route-groups)

Route groups allow you to share route attributes , across a large number of routes without Needing to define Those attributes on each single route . Shared attributes are specified in an array format as the first parameter.

```
    $app->group('/users', function () use ($app) {
        $this->get('', function ());
        //http://example.com/newbie/public/users
        $this->get('/create', function());
        //http://example.com/newbie/public/users/create
    });
```

##### Route Controller:

[](#route-controller)

```
    $app->group('/users', function () use ($app) {
        $controller = new RDuuke\Newbie\Controllers\UsersController($app);
        $this->get('', $controller('index'));
        $this->get('/create', $controller('create'));
    });
    ó
    // index routes (homepage, about, etc)
    $app->group('', function () use ($app) {
        $controller = new App\Controller\IndexController($app);
        $this->get('/', $controller('index'));
        $this->get('/contact', $controller('contact'));
    });
```

#### Controllers:

[](#controllers)

##### Defining Controllers:

[](#defining-controllers)

Below is an example of a basic controller class. Note that the controller extends the Controller class included with `Newbie(Slim3/Controllers)`. The Controller class provides a few convenience,

```
