Learn Bone MVC Framework

It's easy to get up and running with a new project

Installation

First make sure you have Composer! Then install Bone.

composer create-project delboy1978uk/bonemvc your/path/here dev-master

or if you haven't installed composer globally ...

php composer.phar create-project delboy1978uk/bonemvc your/path/here dev-master

Docker Dev Box

Bone comes with a docker-compose.yml in the project, so you can instantly get a dev server running if you use Docker (Tested using a default VirtualBox VM). Just add this to your hosts file
awesome.scot 192.168.99.100

docker-machine start eval $(docker-machine env) cd /path/to/project docker-compose up

Then you can access the site at https://awesome.scot in your browser. Of course if you don't use docker you can add it to your LAMP stack in the usual way.

Configure

You can see a config, data, public, and src folder. Leave be vendor folder, that's where composer installs project dependencies.

Make the data folder writable. 777 gives everyone write access, so instead set it to 775 with yer Apache user in the group.

chmod -R 775 data

In your Apache virtual hosts, set the document root as the public folder

<VirtualHost *:80> DocumentRoot "/var/www/bonemvc/public" ServerName awesome.scot SetEnv APPLICATION_ENV development <Directory "/var/www/bonemvc"> DirectoryIndex index.php FallbackResource /index.php Options -Indexes +FollowSymLinks AllowOverride all Require all granted </Directory> </VirtualHost>

The config folder

You can drop in any number of .php files into the config/ folder. Make sure they return an array with the config . You can override configuration based on environment var APPLICATION_ENV, so for instance if the environment was productionit would load the additional config the production subdirectory.

There are several config files by default:

db.php i18n.php logs.php mail.php routes.php templates.php

In your config files, you can add anything you want. It gets stored in the Bone\Mvc\Registry.


Database

Set your default db credentials in the main config/db.php, and any environment specific configs in a subdirectory

'db' => array( 'host' => '127.0.0.1', 'database' => 'bone', 'user' => 'LeChuck', 'pass' => 'monkeyIsland' ),

Internationalisation

Bone supports translation into different locales. Translation files (gettext .po and .mo) should be placed in data/translations, under a subdirectory of the locale, eg data/translations/en_GB/en_GB.po. You can set the default locale and an array of supported locales.

<?php return [ 'i18n' => [ 'translations_dir' => 'data/translations', 'type' => \Zend\I18n\Translator\Loader\Gettext::class, 'default_locale' => 'en_PI', 'supported_locales' => ['en_PI', 'en_GB', 'nl_BE', 'fr_BE'], ] ];

To use the translator, you can simply call:To use the translator, you can simply call:

// from a controller: $this->getTranslator()->translate('placeholder.string'); // to set locale $this->getTranslator()->setLocale($locale); // from a view file: $this->t('placeholder');

Logs

Bone uses monolog/monolog, and logs can be found in data/logs.Currently we only support writing to files, but you can add as many channels as you like:

<?php return [ 'log' => [ 'channels' => [ 'default' => 'data/logs/default_log', ], ], ];

To use the logger in a controller:

$this->getLog()->debug($message) // or error(), etc, see PSR-3

Mail

Bone uses Zend Mail. To configure the mail client, just drop in your config (see zend mail docs)

<?php return [ 'mail' => [ 'name' => '127.0.0.1', 'host' => 'localhost', 'port' => 25, // 'connection_class' => 'login', // plain, login, crammd5 // 'connection_config' => [ // 'username' => 'user', // 'password' => 'pass', // ], ], ];

If you are using the Docker Box provided by bone, you also have the awesome MailHog at your disposal. Browse to awesome.scot:8025 and you'll see a catch all email inbox, so you never need to worry about development emails reaching the real world.


Routes

Routes follow a default pattern of /controller/action/param/value/nextparam/nextvalue/etc/etc
You can also override routes by defining them in the config array:

<?php return [ 'routes' => [ '/' => [ 'controller' => 'index', 'action' => 'index', 'params' => [], ], '/:locale' => [ 'controller' => 'index', 'action' => 'index', 'params' => [], ], '/optional[/:id]' => [ 'controller' => 'index', 'action' => 'index', 'params' => [], ], ], ];

When defining routes, mandatory variables in the uri have a colon like :id
Optional uri vars have [ ] surrounding them like [:id]


Layouts

Ignore this config. It's old deprecated nonsense.