API16

JView/get: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Method to get data from a registered model or a property of the view <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JView/get|Edit...
 
m clean up
Line 2: Line 2:
Method to get data from a registered model or a property of the view
Method to get data from a registered model or a property of the view


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


{{Description:JView/get}}
 
{{subst:Description:JView/get}}


===Syntax===
===Syntax===
Line 69: Line 67:
</source>
</source>


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


===Examples===
===Examples===

Revision as of 14:37, 24 March 2017

Description

Method to get data from a registered model or a property of the view


{{subst:Description:JView/get}}

Syntax

get($property, $default=null)
Parameter Name Default Value Description
$property The name of the method to call on the model, or the property to get
$default null The name of the model to reference, or the default value [optional]

Returns

mixed The return value of the method

Defined in

libraries/joomla/application/component/view.php

Importing

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

Source Body

public function get($property, $default = null)
{

        // If $model is null we use the default model
        if (is_null($default)) {
                $model = $this->_defaultModel;
        } else {
                $model = strtolower($default);
        }

        // First check to make sure the model requested exists
        if (isset($this->_models[$model]))
        {
                // Model exists, lets build the method name
                $method = 'get'.ucfirst($property);

                // Does the method exist?
                if (method_exists($this->_models[$model], $method))
                {
                        // The method exists, lets call it and return what we get
                        $result = $this->_models[$model]->$method();
                        return $result;
                }

        }

        // degrade to JObject::get
        $result = parent::get($property, $default);
        return $result;

}


{{subst:SeeAlso:JView/get}}

Examples

<CodeExamplesForm />