FOF30\View\View::get PHP Method

get() public method

Method to get data from a registered model or a property of the view
public get ( string $property, string $default = null, string $modelName = null ) : mixed
$property string The name of the method to call on the Model or the property to get
$default string The default value [optional]
$modelName string The name of the Model to reference [optional]
return mixed The return value of the method
    public function get($property, $default = null, $modelName = null)
    {
        // If $model is null we use the default model
        if (is_null($modelName)) {
            $model = $this->defaultModel;
        } else {
            $model = $modelName;
        }
        // First check to make sure the model requested exists
        if (isset($this->modelInstances[$model])) {
            // Model exists, let's build the method name
            $method = 'get' . ucfirst($property);
            // Does the method exist?
            if (method_exists($this->modelInstances[$model], $method)) {
                // The method exists, let's call it and return what we get
                $result = $this->modelInstances[$model]->{$method}();
                return $result;
            } else {
                $result = $this->modelInstances[$model]->{$property}();
                if (is_null($result)) {
                    return $default;
                }
                return $result;
            }
        } else {
            if (@isset($this->{$property})) {
                return $this->{$property};
            } else {
                return $default;
            }
        }
    }