Módulos
v4Módulos são a forma principal de estender a MuCRM. Na v4 ficam em app/modules/(antes app/Plugins/). Cada módulo é isolado: rotas, handlers, models e views próprios.
Estrutura
app/modules/billing/
├── routes.php
├── handlers/
│ ├── web_handler.php
│ └── admin/
│ └── settings_handler.php
├── models/
│ └── billing_plan.php
└── views/
├── index.mucrm.php
└── assets/
├── css/billing.css
└── js/billing.jsRotas
routes.php é carregado automaticamente no boot:
use MUCRM\engine\support\facades\uri;
use MUCRM\modules\billing\handlers\web_handler;
uri::get('/billing', [web_handler::class, 'index'])->name('billing.index');Handler
namespace MUCRM\modules\billing\handlers;
use MUCRM\engine\support\{request, responder};
use MUCRM\http\handler;
class web_handler extends handler
{
protected string $layout = '_layouts.app';
public function index(request $req, responder $res)
{
return $this->view('Billing.index', [
'plans' => billing_plan::where('active', 1)->get(),
])->title('Planos');
}
}plug() — widgets na home
// Handler retorna dados (não view):
public function latest() {
return ['posts' => post::limit(5)->get()];
}
// Na view do tema:
<?php $data = plug('posts::home@latest'); ?>Formato: modulo::handler@metodo
Criar um módulo novo
- Criar
app/modules/meu_modulo/ - Handler com namespace
MUCRM\modules\meu_modulo\handlers routes.phpcomuri::get(...)- Views em
views/*.mucrm.php composer dump-autoload -o
Veja também Assets eCriando Módulos.