Add complete Acai development documentation

- CLAUDE.md: expanded with critical rules, hook syntax, DB conventions, web-base endpoint
- docs/modular-system.md: modules, general sections, global vars, multiv2
- docs/builder-fields.md: all field types, c-if/c-for/c-class, c-form, built-in components
- docs/twig-filters.md: get, hook, module, queryDB, imagec, translate, raw, etc.
- docs/hooks-and-api.md: PHP hooks, CmsApi CRUD, table schemas, field formats
- docs/css-js-conventions.md: Tailwind, BEM, CSS vars, Vue 3 integration, CmsApi JS

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jordan
2026-03-09 18:53:10 +00:00
parent 8f76455c96
commit 963174b4c4
6 changed files with 645 additions and 67 deletions

View File

@@ -2,43 +2,141 @@
## Hooks
Hooks are PHP files in the `hooks/` directory that execute server-side logic at specific lifecycle points.
Hooks are PHP files in the `hooks/` directory that execute server-side logic. They can also live inside a module at `template/estandar/modulos/<module-id>/hook.php`.
### Hook Types
### How to Call Hooks
<!-- TODO: Document hook types (before_page, after_page, on_form, on_api, cron, etc.) -->
**From Twig:**
```twig
{{ 'hooks/module_id/' | hook({param1: 'value1', param2: variable}) }}
```
### Hook File Naming
**From HTML (with result):**
```html
<hook result="myVar" endpoint="/hooks/module_id/" :param1="value1" :param2="'string'"></hook>
<p>{{ myVar }}</p>
```
<!-- TODO: Document naming conventions and how the CMS discovers hooks -->
**From JavaScript:**
```js
CmsApi.hook('/hooks/module_id/', { param1: 'value1' }, function(response) {
console.log(response);
});
```
### Hook Examples
**From c-form:**
Hooks are automatically triggered on form submission when configured.
<!-- TODO: Add practical examples of common hooks -->
### Hook Parameters
Parameters are received as PHP variables:
```php
<?php
// Called with: 'hooks/my_hook/' | hook({category: 'electronics', limit: 10})
// Available as:
$category; // 'electronics'
$limit; // 10
```
### Hook Return Values
Hooks can `echo` or `return` values. When called from Twig or `<hook>` tag, the output is captured into the result variable.
## CmsApi
## CmsApi (PHP)
The `CmsApi` class provides methods to interact with the CMS from hooks.
Server-side API for database operations. Available in all hooks.
<!-- TODO: Document main CmsApi methods (getPage, getRecord, createRecord, updateRecord, etc.) -->
### Read Records
```php
// Get all records
$products = CmsApi::get('productos');
// With WHERE condition
$active = CmsApi::get('productos', ['active' => 1]);
// With order and limit
$latest = CmsApi::get('noticias', [], 'fecha DESC', 5);
// With operators
$expensive = CmsApi::get('productos', ['precio' => ['>=' => 100]]);
$search = CmsApi::get('productos', ['nombre' => ['LIKE' => '%keyword%']]);
$inList = CmsApi::get('productos', ['categoria_num' => ['IN' => [1, 2, 3]]]);
```
### Insert Records
```php
$newRecord = CmsApi::insert('contacto', [
'nombre' => 'John',
'email' => 'john@example.com',
'mensaje' => 'Hello',
]);
```
### Update Records
```php
CmsApi::update('productos',
['precio' => 29.99, 'activo' => 1], // fields to update
['num' => 42] // where condition
);
```
### Delete Records
```php
CmsApi::delete('productos', ['num' => 42]);
```
### Important Rules
- Table names **without** `cms_` prefix
- Primary key is always `num`, never `id`
- Upload fields are handled separately (not via insert/update)
- Operators: `=`, `!=`, `>`, `>=`, `<`, `<=`, `LIKE`, `IN`
## CmsApi (JavaScript — Client-Side)
```js
// Hook call
CmsApi.hook('/hooks/module_id/', { param: 'value' }, function(response) {
// response is the hook output
});
// Record operations (if exposed via hooks)
CmsApi.get('tableName', { where: conditions }, function(records) {
// records array
});
```
## CocoDB
`CocoDB` is the database abstraction layer for Acai.
Low-level database abstraction layer. Use when CmsApi is too high-level.
<!-- TODO: Document CocoDB usage (query, insert, update, delete, transactions) -->
<!-- TODO: Document CocoDB methods (query, insert, update, delete, transactions) -->
## Database Operations
## Table Schemas
### Direct Queries
Table schemas are stored as JSON in `cms/data/schema/`. Each file defines:
- Field names and types
- Validation rules
- Relationships (foreign keys)
- Display configuration
<!-- TODO: Document how to run raw SQL queries from hooks -->
### Field Format Types
### Table Schemas
Table schemas are stored as JSON files in `cms/data/schema/`. Each file defines the fields, types, and configuration of a CMS table.
<!-- TODO: Document schema format and how to create/modify tables -->
| Type | PHP Format | Notes |
|------|-----------|-------|
| Text | String | Plain text |
| Date/time | `YYYY-MM-DD HH:mm:ss` | MySQL datetime format |
| Checkbox | `1` or `0` | Boolean as integer |
| WYSIWYG | HTML string | Rich text with Tailwind classes |
| List | String or num | Foreign key if linked to table |
| Multivalores | JSON string | Serialized array |
| Upload | — | Handled separately, never in insert/update |