====== JView ====== {#JAPI Joomla.Framework Application JView #} JView is the base class for a Joomla! view. This class is designed to be used within the Joomla! MVC framework, although it can be used outside of it as well. It contains holding methods for displaying presentation data. ===== Methods ===== ^ Method ^ Description ^ | [[JView-__construct|{{references:Method.png?nolink}}]] [[JView-__construct|__construct]] | Constructor for the JView class. Setups up paths and configuration values. | | [[JView-addEscape|{{references:Method.png?nolink}}]] [[JView-addEscape|addEscape]] | Adds to the callbacks used when calling JView::escape(). | | [[JView-addHelperPath|{{references:Method.png?nolink}}]] [[JView-addHelperPath|addHelperPath]] | Adds to the stack of helper script paths in LIFO order. | | [[JView-addTemplatePath|{{references:Method.png?nolink}}]] [[JView-addTemplatePath|addTemplatePath]] | Adds to the stack of view script paths in LIFO order. | | [[JView-assign|{{references:Method.png?nolink}}]] [[JView-assign|assign]] | Assigns variables to the view script via differing strategies.

This method is overloaded; you can assign all the properties of an object, an associative array, or a single value by name.

You are not allowed to set variables that begin with an underscore; these are either private properties for JView or private variables within the template script itself.

  1.  $view =new JView();
  2.  
  3.  // assign directly
  4.  $view->var1 'something';
  5.  $view->var2 'else';
  6.  
  7.  // assign by name and value
  8.  $view->assign('var1''something');
  9.  $view->assign('var2''else');
  10.  
  11.  // assign by assoc-array
  12.  $ary array('var1' => 'something''var2' => 'else');
  13.  $view->assign($obj);
  14.  
  15.  // assign by object
  16.  $obj new stdClass;
  17.  $obj->var1 'something';
  18.  $obj->var2 'else';
  19.  $view->assign($obj);

| | [[JView-assignRef|{{references:Method.png?nolink}}]] [[JView-assignRef|assignRef]] | Assign variable for the view (by reference).

You are not allowed to set variables that begin with an underscore; these are either private properties for JView or private variables within the template script itself.

  1.  $view new JView();
  2.  
  3.  // assign by name and value
  4.  $view->assignRef('var1'$ref);
  5.  
  6.  // assign directly
  7.  $view->ref =$var1;

| | [[JView-display|{{references:Method.png?nolink}}]] [[JView-display|display]] | Execute and display a template script. | | [[JView-escape|{{references:Method.png?nolink}}]] [[JView-escape|escape]] | Applies escaping to a value.

You can override the predefined escaping callbacks by passing added parameters as replacement callbacks.

  1.  // use predefined callbacks
  2.  $result $view->escape($value);
  3.  
  4.  // use replacement callbacks
  5.  $result $view->escape(
  6.      $value,
  7.      'stripslashes',
  8.      'htmlspecialchars',
  9.      array('StaticClass''method'),
  10.      array($object$method)
  11.  );

| | [[JView-get|{{references:Method.png?nolink}}]] [[JView-get|get]] | Method to get data from a registered model | | [[JView-getLayout|{{references:Method.png?nolink}}]] [[JView-getLayout|getLayout]] | Get the layout. | | [[JView-getModel|{{references:Method.png?nolink}}]] [[JView-getModel|getModel]] | Method to get the model object | | [[JView-getName|{{references:Method.png?nolink}}]] [[JView-getName|getName]] | Method to get the view name

The model name by default parsed using the classname, or it can be set by passing a $config['name'] in the class constructor

| | [[JView-loadHelper|{{references:Method.png?nolink}}]] [[JView-loadHelper|loadHelper]] | Load a helper file | | [[JView-loadTemplate|{{references:Method.png?nolink}}]] [[JView-loadTemplate|loadTemplate]] | Load a template file -- first look in the templates folder for an override | | [[JView-setEscape|{{references:Method.png?nolink}}]] [[JView-setEscape|setEscape]] | Clears then sets the callbacks to use when calling JView::escape().

Each parameter passed to this function is treated as a separate callback. For example:

  1.  $view->setEscape(
  2.      'stripslashes',
  3.      'htmlspecialchars',
  4.      array('StaticClass''method'),
  5.      array($object$method)
  6.  );

| | [[JView-setLayout|{{references:Method.png?nolink}}]] [[JView-setLayout|setLayout]] | Sets the layout name to use | | [[JView-setLayoutExt|{{references:Method.png?nolink}}]] [[JView-setLayoutExt|setLayoutExt]] | Allows a different extension for the layout files to be used | | [[JView-setModel|{{references:Method.png?nolink}}]] [[JView-setModel|setModel]] | Method to add a model to the view. We support a multiple model single

view system by which models are referenced by classname. A caveat to the classname referencing is that any classname prepended by JModel will be referenced by the name without JModel, eg. JModelCategory is just Category.

| | [[JView-_addPath|{{references:Method.png?nolink}}]] [[JView-_addPath|_addPath]] | Adds to the search path for templates and resources. | | [[JView-_setPath|{{references:Method.png?nolink}}]] [[JView-_setPath|_setPath]] | Sets an entire array of search paths for templates or resources. | ---- ~~DISCUSSION~~