Overview
Sistema Magdaleno follows the CakePHP 1.3 MVC (Model-View-Controller) architecture pattern. The application is organized into distinct layers that separate business logic, data access, and presentation concerns.Directory Structure
Controllers
Location
app/controllers/
Available Controllers
| Controller | Purpose |
|---|---|
denuncias_controller.php | Complaint/report management |
galleries_controller.php | Image gallery CRUD operations |
groups_controller.php | User group & permission management |
locales_controller.php | Business location management |
pages_controller.php | Static page handling |
promos_controller.php | Promotional content management |
registers_controller.php | User registration & campaigns |
users_controller.php | User authentication & profile management |
ventas_controller.php | Sales/transaction handling |
videos_controller.php | Video content management |
Base Controller (AppController)
File:app/app_controller.php
All controllers extend AppController, which provides shared functionality:
Key Methods
beforeFilter() Executes before every controller action:- Scans all controllers in
app/controllers/ - Creates ACO nodes for each controller
- Creates ACO nodes for each public action
- Supports plugin controllers
Controller Naming Convention
- File:
{plural_name}_controller.php(e.g.,users_controller.php) - Class:
{PluralName}Controller(e.g.,UsersController) - Extends:
AppController
Models
Location
app/models/
Available Models
| Model | Database Table | Purpose |
|---|---|---|
User | users | User accounts |
Group | groups | User groups |
Gallery | galleries | Image galleries |
Archivo | archivos | Uploaded files |
Video | videos | Video content |
Category | categories | Content categories |
Locale | (locales table) | Business locations |
Campana | campanas | Marketing campaigns |
Register | registers | User registrations |
Denuncia | (denuncias table) | Complaints/reports |
Aco | acos | ACL objects |
Aro | aros | ACL requesters |
ArosAco | aros_acos | ACL permissions junction |
Model Naming Convention
- File:
{singular_name}.php(e.g.,user.php) - Class:
{SingularName}(e.g.,User) - Extends:
AppModel - Table:
{plural_name}(e.g.,users)
Model Associations
belongsTo
hasMany
hasAndBelongsToMany (HABTM)
Model Behaviors
Tree Behavior (for nested data):Validation
Models define validation rules:Views
Location
app/views/
View Structure
View Naming Convention
- File:
{action_name}.ctp(e.g.,index.ctp,add.ctp) - Location:
views/{controller}/{action}.ctp
Automatic View Rendering
CakePHP automatically renders views based on controller/action:CakePHP Conventions
File Naming
| Type | Convention | Example |
|---|---|---|
| Controller | {plural}_controller.php | users_controller.php |
| Model | {singular}.php | user.php |
| View | {action}.ctp | index.ctp |
| Helper | {name}_helper.php | form_helper.php |
| Component | {name}_component.php | auth_component.php |
| Behavior | {name}_behavior.php | tree_behavior.php |
Class Naming
| Type | Convention | Example |
|---|---|---|
| Controller | {PluralName}Controller | UsersController |
| Model | {SingularName} | User |
| Helper | {Name}Helper | FormHelper |
| Component | {Name}Component | AuthComponent |
| Behavior | {Name}Behavior | TreeBehavior |
Database Conventions
| Item | Convention | Example |
|---|---|---|
| Table | {plural}_name | users, galleries |
| Primary Key | id or {singular}_id | id_usuario |
| Foreign Key | {singular}_id{field} | usuario_id_usuario |
| Junction Table | {table1}_{table2} | archivos_galleries |
URL Routing
CakePHP follows convention-based routing:Components
Location:app/controllers/components/
Reusable controller logic shared across multiple controllers.
Built-in Components Used
- Auth: User authentication and authorization
- Acl: Access Control List management
- Session: Session data management
- Email: Email sending functionality
- PasswordHelper: Custom password utilities
Configuration
Key Configuration Files
app/config/core.php- Core application settingsapp/config/database.php- Database connection settingsapp/config/routes.php- Custom URL routing rulesapp/config/bootstrap.php- Application bootstrap code
Application Flow
Best Practices
Controller Best Practices
- Keep controllers thin - Business logic belongs in models
- Use beforeFilter() for shared setup logic
- Redirect after POST - Prevent form resubmission
- Set proper flash messages - Inform users of results
Model Best Practices
- Define all associations - Enable automatic data fetching
- Use validation rules - Ensure data integrity
- Add custom find methods - Encapsulate complex queries
- Use behaviors - Share logic across models
View Best Practices
- Use elements - Reuse common view fragments
- Use helpers - Keep views clean of complex logic
- Separate layouts - Different designs for different sections
- Escape output - Prevent XSS attacks with
h()
Related Documentation
- Database Schema - Complete database structure
- Authentication - ACL and Auth implementation