This site is built with Viewi itself. It is experimental and still in development. If you see any bugs please do not hesitate and open an issue or DM me on Twitter.

Installation

Install The Viewi Package

> composer require viewi/viewi

Create a new app with Viewi CLI tool

To create a default viewi application automatically run command:

> vendor/bin/viewi new [-f folder] [-e] [-a]

Where -f folder is an optional parameter and can be omitted.

Where -a means you are going to use an adapter and do not need to modify the index.php file. Usually you use -a when installing Viewi with another framework. It is an optional parameter and can be omitted.

And -e is an optional as well. But if present, generates demo components. For example:

> vendor/bin/viewi new
or
> vendor/bin/viewi new -f myViewiApp
or
> vendor/bin/viewi new -f src/ViewiApp
or
> vendor/bin/viewi new -e
or
> vendor/bin/viewi new -f myViewiApp -e

It will generate for you the default code for using Viewi as a standalone application in one of these files: /index.php or /public/index.php.

If you specified folder parameter, your components will be located in that folder, otherwise it will use one of these: viewi-app/ or src/ViewiApp/.

To use it with the Apache or NGINX you need to make sure that all requests are coming to the index.php file by using rewrite rules.

Viewi does not support running from a subdirectory yet. Please adapt your app accordingly.

Create a new app manually

To create a new app manually follow the next steps

Include vendor autoload

In your /public/index.php put this if it's not there already:

require __DIR__ . '/../vendor/autoload.php';

Create folders for your components

Like this:
  • viewi-app/
  • viewi-app/build for compiled server-side components
  • viewi-app/Components for your front-end application (templates, services, models)
You can chose your own folder instead of viewi-app/.

Create the next files

Config file viewi-app/config.php:

<?php

use Viewi\PageEngine;

const VIEWI_COMPONENTS = __DIR__ . '/Components';
const PUBLIC_FOLDER = __DIR__ . '/../public/';

return [
    PageEngine::SOURCE_DIR =>  VIEWI_COMPONENTS,
    PageEngine::SERVER_BUILD_DIR =>  __DIR__ . '/build',
    PageEngine::PUBLIC_ROOT_DIR => PUBLIC_FOLDER,
    PageEngine::DEV_MODE => true,
    PageEngine::RETURN_OUTPUT => true,
    PageEngine::COMBINE_JS => true
];

Routes file viewi-app/routes.php:

<?php

use Viewi\Routing\Route;

// routes here

Viewi boot file viewi-app/viewi.php:

<?php

use Viewi\App;

$config = require 'config.php';
include __DIR__ . '/routes.php';
App::init($config);

Include Viewi boot file

In your /public/index.php put these:

include __DIR__ . '/../viewi-app/viewi.php';
Viewi\App::handle();

Now you are ready to create your first component