JControllerForm/ construct

From Joomla! Documentation

< API16:JControllerForm

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.



<! removed transcluded page call, red link never existed >


Parameter Name Default Value Description
$config array() An optional associative array of configuration settings.

Defined in



jimport( 'joomla.application.component.controllerform' );

Source Body

public function __construct($config = array())

        // Guess the option as com_NameOfController
        if (empty($this->_option)) {
                $this->_option = 'com_'.strtolower($this->getName());

        // Guess the context as the suffix, eg: OptionControllerContent.
        if (empty($this->_context)) {
                $r = null;
                if (!preg_match('/(.*)Controller(.*)/i', get_class($this), $r)) {
                        JError::raiseError(500, 'JController_Error_Cannot_parse_name');
                $this->_context = strtolower($r[2]);

        // Guess the item view as the context.
        if (empty($this->_view_item)) {
                $this->_view_item = $this->_context;

        // Guess the list view as the plural of the item view.
        if (empty($this->_view_list))
                // @TODO Probably worth moving to an inflector class based on http://kuwamoto.org/2007/12/17/improved-pluralizing-in-php-actionscript-and-ror/

                // Simple pluralisation based on public domain snippet by Paul Osman
                // For more complex types, just manually set the variable in your class.
                $plural = array(
                        array( '/(x|ch|ss|sh)$/i',              "$1es"),
                        array( '/([^aeiouy]|qu)y$/i',   "$1ies"),
                        array( '/([^aeiouy]|qu)ies$/i', "$1y"),
                        array( '/(bu)s$/i',                             "$1ses"),
                        array( '/s$/i',                                 "s"),
                        array( '/$/',                                   "s")

                // check for matches using regular expressions
                foreach ($plural as $pattern)
                        if (preg_match($pattern[0], $this->_view_item)) {
                                $this->_view_list = preg_replace( $pattern[0], $pattern[1], $this->_view_item);

        // Apply, Save & New, and Save As copy should be standard on forms.
        $this->registerTask('apply',            'save');
        $this->registerTask('save2new',         'save');
        $this->registerTask('save2copy',        'save');

<! removed transcluded page call, red link never existed >


Code Examples