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.
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 [];
Fill the routes.php
return [
'foo' => [
'route' => '/foo',
'paths' => [
'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\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
The simplest structure | Full structure |
---|---|
|
|
{scope} - Optional. It can be for example "frontend" or "backend" or "dashboard" or whatever you want.