Development

These FAQs briefly summarise key concepts regarding developing with Composr and how to use its framework.

For more information, check out these tutorials:

Note that these FAQs only cover the introduction section of the codebook. The tutorial linked above contains a Table of Contents for more advanced concepts.
Question What are the main components of the Composr framework?
Answer Composr consists of:
  • Modules: PHP files that provide related screens, forming the building blocks of addons.
  • Comcode: Text files containing content written in a simplified markup language.
  • HTML: Files containing standard HTML for web pages.
  • Sources: PHP code files for the core API and functionality.
  • Hooks: PHP files enabling addons to interact and extend each other's functionality.
  • Blocks/Miniblocks: Reusable components for displaying dynamic content within pages.
  • Themes: Folders containing images, CSS, and templates to define the look and feel.
  • Language files: Files holding text strings for multilingual support.
Question How can I customize Composr without modifying the core files?
Answer Composr offers a robust override system. Instead of altering the original files, create a parallel structure within _custom directories. For example, to modify site/pages/modules/polls.php, place your customized version in site/pages/modules_custom/polls.php.

The tutorials outline additional information on how to utilise overrides.
Question What are the different ways to extend Composr functionality?
Answer You can extend Composr through:
  • File overrides: Replacing existing source files with modified versions in _custom directories.
  • New Modules/Mini-modules: Creating new modules for complex functionalities or mini-modules for simpler ones.
  • New Blocks/Miniblocks: Adding reusable content blocks.
  • New API code: Adding new PHP files to the sources_custom directory.
  • Hooks: Writing hooks to add features to specific areas of functionality.
Question Can you give an example of creating a new module?
Answer Imagine creating a "Testing" module to manage collaborative testing:
  • Define purpose: Allow testers to add, assign, and track tests, with security and forum integration.
  • Design database: Plan the necessary database tables and fields to store the module's data.
  • Create module shell: Write the basic module structure based on standard Composr modules.
  • Define screens: Identify the module's screens and code their corresponding functions.
  • Utilize API functions: Use Composr's built-in API functions like create_table, add_privilege, and do_template to implement functionality.
Question How can I export and import custom addons?
Answer Composr allows exporting addons as TAR files, containing all necessary files and an addon.inf file for metadata. You can import these addons to share and reuse them across different Composr installations.

To do this, make your necessary files for the addon in the Composr installation, and then go under Admin Zone > Structure > Addons > Export addon. You can select the relevant files for the addon, provide information about the addon, and then download the TAR file (which can then be imported on other Composr sites).
Question What is the purpose of the Code Editor?
Answer The Code Editor is a web-based tool for editing Composr code files directly on the server. It requires password authentication and automatically manages overrides within _custom directories.

To access it, go to yourbaseurl/code_editor.php.
Question Where can I find resources for learning PHP programming?
Answer While Composr documentation doesn't cover basic PHP, resources like the official PHP documentation (

PHP: Hypertext Preprocessor

PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.

View

), online tutorials, and the Composr API guide can help you learn.
Question What are some key coding standards in Composr?
Answer Composr emphasizes clean, well-structured code with a focus on readability and maintainability. Key standards include proper indentation, consistent use of comments, and clear function headers with type definitions. Remember: beautiful code leads to better functionality and collaboration!
Question What tools are available for debugging Composr code?
Answer Composr offers a code quality checker addon that helps identify various types of errors, including parser errors, run-time errors, and logical errors. This tool can significantly reduce debugging time and enhance code reliability. It is available through the testing_platform addon.
Question How does Composr implement the Model-View-Controller (MVC) pattern?
Answer
  • Model/API: The sources directory primarily houses scripts forming the Model/API, handling data logic and business rules.
  • View: Templates in themes/default/templates represent the View, responsible for presenting data to the user. Comcode pages can also be considered part of the View.
  • Controller: Entry scripts like index.php and site/dload.php act as front controllers, directing requests. Modules and blocks, residing in */pages/modules and sources/[mini]blocks, respectively, serve as controllers, managing user interactions and determining which View to render.
Question What are the advantages of using Composr's JavaScript libraries?
Answer Composr's JavaScript libraries like $cms, $util, and $dom offer several advantages:
  • Organization: They provide a structured way to access Composr-specific functionalities, avoiding global namespace pollution.
  • Abstraction: They encapsulate common tasks, simplifying DOM manipulation, form handling, and interaction with Composr's UI.
  • Consistency: They offer a consistent API across different parts of Composr.
Question How do data-tpl and data-view behaviors work in Composr's JavaScript?
Answer Composr uses data-tpl and data-view behaviors for associating HTML templates and JavaScript views, respectively. This facilitates clean separation of presentation and logic:
  • data-tpl: Used with the $cms.behaviors.initializeTemplates function and PARAMS_JSON tempcode directive to bind JavaScript logic to HTML templates.
  • data-view: Used with the $cms.behaviors.initializeViews function to associate JavaScript view classes (inheriting from $cms.View) with specific HTML elements.