Actions

API15

JController/ construct

From Joomla! Documentation

< API15:JController
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.

Contents

Description

Constructor.

[<! removed edit link to red link >]

<! 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 private 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 edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />