API15

Difference between revisions of "JController/getView"

From Joomla! Documentation

< API15:JController
(New page: ===Description=== Method to get a reference to the current view and load it if necessary. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JController...)
 
Line 9: Line 9:
  
 
===Syntax===
 
===Syntax===
<source lang="php">getView($name= '', $type= '', $prefix= '', $config=array())</source>
+
<source lang="php">& getView($name= '', $type= '', $prefix= '', $config=array())</source>
  
 
  {| class="wikitable"
 
  {| class="wikitable"
Line 44: Line 44:
 
===Source Body===
 
===Source Body===
 
<source lang="php">
 
<source lang="php">
function getView($name = '', $type = '', $prefix = '', $config = array())
+
function &getView( $name = '', $type = '', $prefix = '', $config = array() )
 
{
 
{
 
         static $views;
 
         static $views;
  
         if (!isset($views)) {
+
         if ( !isset( $views ) ) {
 
                 $views = array();
 
                 $views = array();
 
         }
 
         }
         if (empty($name)) {
+
 
 +
         if ( empty( $name ) ) {
 
                 $name = $this->getName();
 
                 $name = $this->getName();
 
         }
 
         }
         if (empty($prefix)) {
+
 
 +
         if ( empty( $prefix ) ) {
 
                 $prefix = $this->getName() . 'View';
 
                 $prefix = $this->getName() . 'View';
 
         }
 
         }
         if (empty($views[$name])) {
+
 
                 if ($view = & $this->_createView($name, $prefix, $type, $config)) {
+
         if ( empty( $views[$name] ) )
 +
        {
 +
                 if ( $view = & $this->_createView( $name, $prefix, $type, $config ) ) {
 
                         $views[$name] = & $view;
 
                         $views[$name] = & $view;
 
                 } else {
 
                 } else {
 
                         $result = JError::raiseError(
 
                         $result = JError::raiseError(
                                 500, JText::_('View not found [name, type, prefix]:')
+
                                 500, JText::_( 'View not found [name, type, prefix]:' )
 
                                         . ' ' . $name . ',' . $type . ',' . $prefix
 
                                         . ' ' . $name . ',' . $type . ',' . $prefix
 
                         );
 
                         );

Revision as of 17:09, 22 March 2010

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Method to get a reference to the current view and load it if necessary.

[Edit Descripton]

Template:Description:JController/getView

Syntax[edit]

& getView($name= '', $type= '', $prefix= '', $config=array())
Parameter Name Default Value Description
$name The view name. Optional, defaults to the controller name.
$type The view type. Optional.
$prefix The class prefix. Optional.
$config array() Configuration array for view. Optional.

Returns[edit]

object Reference to the view or an error.

Defined in[edit]

libraries/joomla/application/component/controller.php

Importing[edit]

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

Source Body[edit]

function &getView( $name = '', $type = '', $prefix = '', $config = array() )
{
        static $views;

        if ( !isset( $views ) ) {
                $views = array();
        }

        if ( empty( $name ) ) {
                $name = $this->getName();
        }

        if ( empty( $prefix ) ) {
                $prefix = $this->getName() . 'View';
        }

        if ( empty( $views[$name] ) )
        {
                if ( $view = & $this->_createView( $name, $prefix, $type, $config ) ) {
                        $views[$name] = & $view;
                } else {
                        $result = JError::raiseError(
                                500, JText::_( 'View not found [name, type, prefix]:' )
                                        . ' ' . $name . ',' . $type . ',' . $prefix
                        );
                        return $result;
                }
        }

        return $views[$name];
}

[Edit See Also] Template:SeeAlso:JController/getView

Examples[edit]

<CodeExamplesForm />