Overview
ThePageController extends SingleController and is specifically designed for handling page-type documents. It inherits all single-document behavior while setting a specific client-side rendering mode for pages.
Class Definition
packages/loopar/core/controller/page-controller.js:5
When to Use
- For creating custom page views in your application
- When building landing pages or informational pages
- For dashboard or portal pages
- When you need single-instance page behavior with specialized rendering
Key Features
- Inherits all SingleController functionality
- Sets client-side rendering mode to ‘page’
- Automatic single-instance behavior (no list views)
- Integrated with web app navigation system
- Optimized for page-type document rendering
Constructor
Configuration object containing controller initialization parameters:
action: The current action being performeddocument: The document type (typically a Page)data: Request datareq: HTTP request objectres: HTTP response object- Other inherited controller properties
Properties
Client-side rendering mode, set to ‘page’ for page-specific rendering logic
Current action being executed (inherited)
Document type name being controlled
Default action, automatically redirected to ‘update’ for single documents
Whether to display sidebar navigation
Inherited Methods
PageController inherits all methods from:- SingleController - Single document management
- BaseController - CRUD operations
- CoreController - Rendering, error handling
- AuthController - Authentication and authorization
Core Methods Available
From SingleController
getParent()
getParent()
Promise<string> - Parent page identifiersendAction(action)
sendAction(action)
action(string) - Action name to execute
Promise<object> - Action execution resultactionView()
actionView()
Promise<object> - Rendered page responsesendDocument(action)
sendDocument(action)
Promise<object> - Rendered page with metadataFrom BaseController
actionUpdate(document)
actionUpdate(document)
Promise<object> - Success message or rendered formactionDelete()
actionDelete()
Promise<object> - Redirect to listFrom CoreController
render(meta)
render(meta)
Promise<object> - Rendered response with metadatasuccess(message, options)
success(message, options)
Promise<object> - Success response with notificationerror(message, options, status)
error(message, options, status)
Promise<object> - Error response with notificationUsage Examples
Creating a Custom Page Controller
Creating a Landing Page
Custom Action for Page Analytics
Integrating with Web App Navigation
Client-Side Rendering
Theclient = 'page' property affects how the page is rendered on the client side:
Best Practices
Page Documents: Use PageController for documents that represent actual pages in your application, not for data entities.
Do’s
- Use for landing pages, dashboards, and custom views
- Override
actionView()to add custom data loading - Implement custom actions for page-specific functionality
- Leverage the parent menu system for navigation
- Track page analytics by extending actionView
Don’ts
- Don’t use for data entities that need CRUD operations
- Don’t expect list views to work (they redirect to update)
- Don’t use for documents that need multiple instances
- Avoid complex business logic in page controllers
Comparison with Other Controllers
| Feature | PageController | SingleController | BaseController | FormController |
|---|---|---|---|---|
| Multiple instances | No | No | Yes | Yes |
| List view | Redirected | Redirected | Yes | Redirected |
| Client mode | ’page’ | Inherited | Dynamic | N/A |
| Best for | Pages/Views | Settings | Data entities | Public forms |
| Single instance | Yes | Yes | No | No |
Related Controllers
- SingleController - Parent class for single documents
- ViewController - Similar purpose with ‘view’ client mode
- BaseController - Core CRUD functionality
- FormController - Form-specific handling
Common Use Cases
- Dashboard Pages: Main application dashboards with aggregated data
- Landing Pages: Public-facing pages with dynamic content
- About/Help Pages: Static or semi-static content pages
- Portal Pages: User-specific portal pages
- Settings Pages: Configuration pages (though SingleController might be more appropriate)
Troubleshooting
Page redirects to update instead of showing content
Page redirects to update instead of showing content
This is expected behavior for single documents. Ensure your route uses the ‘view’ action explicitly:
Client rendering doesn't use 'page' mode
Client rendering doesn't use 'page' mode
Check that the document Entity type is set correctly and that no other controller properties override the client setting.
Cannot create new page instances
Cannot create new page instances
PageController inherits from SingleController, which prevents multiple instances. Use BaseController for multi-instance documents.