Files
claude-plugins/perfex-dev/skills/perfex-views/SKILL.md
T

5.0 KiB

name, description, layer
name description layer
perfex-views Views e templates para módulos Perfex CRM — init_head(), init_tail(), views admin e cliente, passagem de dados. Baseado apenas na documentação oficial. wiki

/perfex-views - Views Perfex CRM

Sistema de views e templates para módulos. Zero assumptions, zero hallucinations - apenas documentação oficial.


Documentação Base


Estrutura de Pastas

modules/meu_modulo/
└── views/
    ├── index.php           # Lista principal
    ├── form.php            # Formulário create/edit
    ├── view.php            # Detalhe
    ├── client_index.php    # Lista cliente
    ├── client_view.php     # Detalhe cliente
    ├── partials/
    │   ├── _table.php      # Partial tabela
    │   └── _filters.php    # Partial filtros
    └── widgets/
        └── dashboard.php   # Widget dashboard

Views Admin (Área Staff)

Template Base Admin

<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php init_head(); ?>

<div id="wrapper">
    <div class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="panel_s">
                    <div class="panel-body">

                        <!-- CONTEÚDO AQUI -->
                        <h4><?php echo _l('meu_modulo_title'); ?></h4>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php init_tail(); ?>
</body>
</html>

Funções Essenciais

Função Descrição
init_head() Inclui header, sidebar, CSS, meta tags
init_tail() Inclui footer, JavaScript, fecha documento

Carregar Views

No Controller

// Básico
$this->load->view('form');

// Com dados
$data = [
    'item' => $item,
    'clients' => $clients,
];
$this->load->view('form', $data);

// Retornar como string (não fazer echo)
$html = $this->load->view('partial', $data, true);

Fora de Controllers (Helpers, Classes)

function meu_modulo_render_widget()
{
    $CI = &get_instance();
    $CI->load->view('meu_modulo/widgets/dashboard');
}

// Com dados
function meu_modulo_render_table($items)
{
    $CI = &get_instance();
    $CI->load->view('meu_modulo/partials/_table', ['items' => $items]);
}

Views Cliente (Área Cliente)

No Controller (ClientsController)

public function index()
{
    $this->data([
        'items' => $items,
        'title' => 'Meu Módulo',
    ]);
    $this->title(_l('meu_modulo_title'));
    $this->view('client_index');
    $this->layout(); // Aplica tema do cliente
}

Template Base Cliente

<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

<div class="panel_s">
    <div class="panel-body">
        <h4 class="no-margin"><?php echo _l('meu_modulo_title'); ?></h4>
        <hr class="hr-panel-heading" />

        <!-- CONTEÚDO -->
        <?php foreach ($items as $item): ?>
            <p><?php echo html_escape($item->name); ?></p>
        <?php endforeach; ?>

    </div>
</div>

Exemplos Completos

Lista com Tabela (Admin)

<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php init_head(); ?>

<div id="wrapper">
    <div class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="panel_s">
                    <div class="panel-body">

                        <div class="_buttons">
                            <?php if (staff_can('create', 'meu_modulo')): ?>
                                <a href="<?php echo admin_url('meu_modulo/create'); ?>"
                                   class="btn btn-primary pull-left">
                                    <i class="fa fa-plus"></i>
                                    <?php echo _l('new_item'); ?>
                                </a>
                            <?php endif; ?>
                        </div>

                        <div class="clearfix"></div>
                        <hr class="hr-panel-heading" />

                        <table class="table table-striped dt-table">
                            <thead>
                                <tr>
                                    <th><?php echo _l('id'); ?></th>
                                    <th><?php echo _l('name'); ?></th>
                                    <th><?php echo _l('created_at'); ?></th>
                                    <th><?php echo _l('options'); ?></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($items as $item): ?>
                                <tr>
                                    <td><?php echo $item->id; ?></td>
                                    <td><?php echo html_escape($item->name); ?></td>