JControllerForm/ construct

From Joomla! Documentation

< API16:JControllerForm
Revision as of 16:35, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.



[Edit Descripton]

Description:JControllerForm/ construct


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
                // 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');

[Edit See Also] SeeAlso:JControllerForm/ construct


<CodeExamplesForm />