API16

JPlugin/ construct: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Constructor <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> </span> {{D...
 
m preparing for archive only
 
(2 intermediate revisions by 2 users not shown)
Line 2: Line 2:
Constructor
Constructor


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JPlugin/__construct|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JPlugin/__construct}}
 
 


===Syntax===
===Syntax===
Line 17: Line 15:
!Description
!Description
|-
|-
|  
| &$subject
|  
|  
|  $subject The object to observe  
|  $subject The object to observe  
Line 64: Line 62:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JPlugin/__construct|Edit See Also]]<nowiki>]</nowiki>
 
</span>
{{SeeAlso:JPlugin/__construct}}


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=__construct
  category=__construct
  category=JPlugin
  category=JPlugin
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>

Latest revision as of 01:59, 25 March 2017

Description

Constructor



Syntax

__construct(&$subject, $config=array())
Parameter Name Default Value Description
&$subject $subject The object to observe
$config array() $config An optional associative array of configuration settings. Recognized key values include 'name', 'group', 'params' (this list is not meant to be comprehensive).

Defined in

libraries/joomla/plugin/plugin.php

Importing

jimport( 'joomla.plugin.plugin' );

Source Body

public function __construct(&$subject, $config = array())
{
        // Get the parameters.
        if (isset($config['params']))
        {
                if ($config['params'] instanceof JParameter) {
                        $this->params = $config['params'];
                } else {
                        $this->params = new JParameter($config['params']);
                }
        }

        // Get the plugin name.
        if (isset($config['name'])) {
                $this->_name = $config['name'];
        }

        // Get the plugin type.
        if (isset($config['type'])) {
                $this->_type = $config['type'];
        }
        $events = get_class_methods($this);
        foreach($events as $event)
        {
                $method = array('event' => $event, 'handler' => array($this, 'onFireEvent'));
                $subject->attach($method);
        }
        parent::__construct($subject);
}



Examples

Code Examples