Login +

Controllers / Components Pattern

Part Components lists the components of the application.

A component is, as its name indicates, a redundant module to the application, which can be used on multiple actions in a flexible manner without having to redevelop redundant treatments.

It’s mapped from 0 to N actions.

In the example, we chose a registration module for a newsletter being present on several pages.

The tree is as follows:

The structure of a Component is as follows:

<?php
/**
 * Controller Component NewsletterController
 *
 * @author SillySmart
 * @copyright SillySmart
 * @package Mvc.Controllers.Components.NewsletterController
 * @see Sls.Controllers.Core.SLS_FrontComponent
 * @since 1.0
 */
class NewsletterController extends SLS_FrontComponent implements SLS_IComponent
{

    public function __construct()
    {
        parent::__construct(true);
    }

    public function constructXML()
    {
        // Write here all your instructions to make your Component configuration with xml by $this->_xmlToolBox
    }

}
?>

The code of your Component will thus be written in constructXML() function

Related :

References

  1. SLS_FrontComponent - Controller FrontComponent - Father's controller of each Component Controller