Module

Modules

Application based on Vegas CMF is divided to modules. Each module has own config file and routes definition. As module we can implement in example: news, user, auth, acl, gallery, settings, contact and whatever you want.

Create module

To create module named "Foo" you have to do the following steps.

cd your-project
mkdir -p app/modules/Foo
touch app/modules/Foo/Module.php

Fill the Module.php file the following content


namespace Foo;

class Module extends \Vegas\Mvc\ModuleAbstract
{
    public function __construct() {
        $this->namespace = __NAMESPACE__;
        $this->dir = __DIR__;
    }
}

All modules are loaded automatically and defined in app/config/modules.php file. When vegas project enviroment is set to "development" mode then list of modules is rebuilt for each request in this file.


Create config

mkdir app/modules/Foo/config
touch app/modules/Foo/config/config.php
touch app/modules/Foo/config/routes.php

Fill the config.php

return array();

Fill the routes.php

return array(
    'foo' => array(
        'route' => '/foo',
        'paths' => array(
            'module' => 'Foo',
            'controller' => 'Frontend\Foo',
            'action' => 'index'
        )
    )
);

Create controller for frontend scope

mkdir app/modules/Foo/controllers
mkdir app/modules/Foo/controllers/frontend
touch app/modules/Foo/controllers/frontend/FooController.php

Fill the FooController.php. (You can also use here CRUD Controller or CRUD Upload Controller)

namespace Foo\Controllers\Frontend;

use Vegas\Mvc\Controller\ControllerAbstract;

class FooController extends ControllerAbstract
{
    public function indexAction()
    {
        //code...
    }
}

Create view for frontend scope

mkdir app/modules/Foo/views
mkdir -p app/modules/Foo/views/frontend/foo
touch app/modules/Foo/views/frontend/foo/index.volt

Fill the index.volt

It works

Module structure

The simplest structure Full structure
Foo/
    - config/
        - config.php
        - routes.php
    - controllers/
        - {scope}/
             - {ControllerName}.php
    - Module.php
Foo/
    - config/
        - config.php
        - routes.php
    - components/
        - {ComponentName_1}.php
        - {ComponentName_2}.php
        ...
        - {ComponentName_n}.php
    - controllers/
        - {scope_1}/
            - {ControllerName_1}.php
            - {ControllerName_2}.php
            ...
            - {ControllerName_n}.php
        - {scope_2}/
            - {ControllerName_1}.php
            - {ControllerName_2}.php
            ...
            - {ControllerName_n}.php
        - {scope_n}/
            - {ControllerName_1}.php
            - {ControllerName_2}.php
            ...
            - {ControllerName_n}.php
    - forms/
        - {FormName_1}.php
        - {FormName_2}.php
        ...
        - {FormName_n}.php
    - models/
        - {ModelName_1}.php
        - {ModelName_2}.php
        ...
        - {ModelName_n}.php
    - services/
        - {ServiceName_1}.php
        - {ServiceName_2}.php
        ...
        - {ServiceName_n}.php
    - views/
        - {scope_1}/
            - {viewName_1}.php
            - {viewName_2}.php
            ...
            - {viewName_n}.php
        - {scope_2}/
            - {viewName_1}.php
            - {viewName_2}.php
            ...
            - {viewName_n}.php
        - {scope_n}/
            - {viewName_1}.php
            - {viewName_2}.php
            ...
            - {viewName_n}.php
    - Module.php

{scope} - it can be for example "frontend" or "backend" or "dashboard" or whatever you want.