API16

JController/ construct: Difference between revisions

From Joomla! Documentation

m removing red link to edit, no existant pages
m clean up
Line 2: Line 2:
Constructor.
Constructor.


<span class="editsection" style="font-size:76%;">
 
<nowiki>[<! removed edit link to red link >]</nowiki>
</span>


<! removed transcluded page call, red link never existed >
<! removed transcluded page call, red link never existed >
Line 97: Line 95:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[<! removed edit link to red link >]</nowiki>
</span>
<! removed transcluded page call, red link never existed >
<! removed transcluded page call, red link never existed >



Revision as of 13:44, 24 March 2017

Description

Constructor.


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

Syntax

__construct($config=array())
Parameter Name Default Value Description
$config array() An optional associative array of configuration settings. Recognized key values include 'name', 'default_task', 'model_path', and 'view_path' (this list is not meant to be comprehensive).

Defined in

libraries/joomla/application/component/controller.php

Importing

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

Source Body

function __construct($config = array())
{
        // Initialize variables.
        $this->_redirect        = null;
        $this->_message         = null;
        $this->_messageType = 'message';
        $this->_taskMap         = array();
        $this->_methods         = array();
        $this->_data            = array();

        // Get the methods only for the final controller class
        $thisMethods    = get_class_methods(get_class($this));
        $baseMethods    = get_class_methods('JController');
        $methods                = array_diff($thisMethods, $baseMethods);

        // Add default display method
        $methods[] = 'display';

        // Iterate through methods and map tasks
        foreach ($methods as $method) {
                if (substr($method, 0, 1) != '_') {
                        $this->_methods[] = strtolower($method);
                        // auto register public methods as tasks
                        $this->_taskMap[strtolower($method)] = $method;
                }
        }

        //set the view name
        if (empty($this->_name)) {
                if (array_key_exists('name', $config))  {
                        $this->_name = $config['name'];
                } else {
                        $this->_name = $this->getName();
                }
        }

        // Set a base path for use by the controller
        if (array_key_exists('base_path', $config)) {
                $this->_basePath        = $config['base_path'];
        } else {
                $this->_basePath        = JPATH_COMPONENT;
        }

        // If the default task is set, register it as such
        if (array_key_exists('default_task', $config)) {
                $this->registerDefaultTask($config['default_task']);
        } else {
                $this->registerDefaultTask('display');
        }

        // set the default model search path
        if (array_key_exists('model_path', $config)) {
                // user-defined dirs
                $this->addModelPath($config['model_path']);
        } else {
                $this->addModelPath($this->_basePath.DS.'models');
        }

        // set the default view search path
        if (array_key_exists('view_path', $config)) {
                // user-defined dirs
                $this->_setPath('view', $config['view_path']);
        } else {
                $this->_setPath('view', $this->_basePath.DS.'views');
        }
}


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

Examples

<CodeExamplesForm />