enindu/slender

Rapid web development environment based on Slim framework

Installs: 20

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:project

v0.1.1 2020-06-17 15:41 UTC

This package is auto-updated.

Last update: 2020-07-08 12:09:26 UTC


README

Rapid web development environment based on Slim framework

Features

Install

Install Slender using Composer or clone repository using Git. If you cloned repository, make sure to install Composer packages using composer install command.

$ composer create-project enindu/slender <project name>
$ git clone https://github.com/enindu/slender.git

Controllers

App controllers can be found at app/Controller/ directory. Every controller class must extends App\Controller\Base class.

namespace App\Controller;

use App\Controller\Base;
use Slim\Psr7\Request;
use Slim\Psr7\Response;

class Example extends Base
{
  public function method(Request $request, Response $response, array $data)
  {
    // Code goes here
  }
}

Get containered packages on controllers by using $this->container variable from Base controller.

$package = $this->container->get('package');

Manage templates on controllers by using $this->view method from Base controller. To pass data as Twig variable, use $this->data variable from Base controller. For more information, refer Twig documentation.

$this->data = [
  'variableOne' => 'Some data',
  'variableTwo' => 'More data'
];

return $this->view($response, 'example.twig');

Send mails on controllers by using $this->mail method from Base controller. For more information, refer Swift Mailer documentation.

$this->mail('base.twig', [
  'subject' => 'Mail Subject',
  'from'    => ['john@example.com' => 'John Doe'],
  'to'      => ['brad@example.com' => 'Brad Doe'],
  'body'    => 'Mail Body'
]);

Manipulate date and time on controllers by using $this->datetime variable from Base controller. For more information, refer Carbon documentation.

$this->datetime

Manage files and directories on controllers by using $this->filesystem variable from Base controller. For more information, refer Filesystem documentation.

$this->filesystem

Validate forms on controllers by using $this->validator method from Base controller. For more information, refer Validation documentation.

$validation = $this->validator($request, [
  'input' => 'required|min:6|max:16'
]);

Routes

App routes can be found at app/routes.php file. For more information, refer Slim documentation.

use App\Controller\Example;

$app->get('/example', Example::class . ':method');

Views

All templates can be found at resources/views/ directory. Slender uses Twig as template engine. You can extend Twig by adding more filters or functions or global variables that can be found at app/Extension/ directory. For more information, refer Twig documentation.

Define assets by using asset filter.

{{ 'css/example.css'|asset }}

Define internal page routes by using page filter.

{{ '/your/route'|page }}

Here're all global variables available.

{# Get app name #}
{{ app.name }}

{# Get app description #}
{{ app.description }}

{# Get app keywords #}
{{ app.keywords }}

{# Get app author #}
{{ app.author }}

{# Get app email #}
{{ app.email }}

{# Get app URL #}
{{ app.url }}