PHP Class AbstractView, atk4

They are used to take user input and return it in appropriate format.
Exibir arquivo Open project: atk4/atk4 Class Usage Examples

Public Properties

Property Type Description
$_tsBuffer
$auto_track_element boolean
$default_controller string automatically.
$dq DB_dsql Using dq property looks obsolete, but left for compatibility
$js of jQuery_Chains
$spot string $spot defines a place on a parent's template where render() will output() resulting HTML.
$template Template Example: $view->template->set('title', $my_title); Assuming you have tag in template file associated with this view - will insert text into this tag.
$template_flush string

Public Methods

Method Description
__clone ( ) For safety, you can't clone views. Use $view->newInstance instead.
_tsBuffer ( $t, $data )
defaultSpot ( ) : string Normally when you add a view, it's output is placed inside tag of its parent view. You can specify a different tag as 3rd argument for the add() method. If you wish for object to use different tag by default, you can override this method.
defaultTemplate ( ) : string This method is commonly redefined to set a default template for an object.
getHTML ( boolean $destroy = true, boolean $execute_js = true ) : string Converting View into string will render recursively and produce HTML.
getJSID ( ) : string
initTemplateTags ( ) This method is called to automatically fill in some of the tags in this view. Normally the call is bassed to $app->setTags(), however you can extend and add more tags to fill.
initializeTemplate ( string $template_spot = null, string | array $template_branch = null ) : AbstractView Called automatically during init for template initalization.
js ( string | boolean | null $when = null, array | jQuery_Chain | string $code = null, string $instance = null ) : jQuery_Chain Views in Agile Toolkit can assign javascript actions to themselves. This is done by calling $view->js() method.
modelRender ( ) When model is specified for a view, values of the model is inserted inside the template if corresponding tags exist.
moveJStoParent ( ) Append our chains to owner's chains. JS chains bubble up to app, which plugs them into template. If the object is being "cut" then only relevant chains will be outputed.
on ( $event, $selector = null, $js = null ) Views in Agile Toolkit can assign javascript actions to themselves. This is done by calling $view->js() or $view->on().
output ( string $txt ) Low level output function which append's to the parent object's template. For normal objects, you simply need to specify a suitable template.
recursiveRender ( ) Recursively renders all views. Calls render() for all or for the one being cut. In some cases you may want to redefine this function instead of render(). The difference is that this function is called before sub-views are rendered, but render() is called after.
region_render ( ) When "cut"-ing using cut_region we need to output only a specified tag. This method of cutting is mostly un-used now, and should be considered obsolete.
render ( ) Default rendering method. Generates HTML presentation of $this view.
setModel ( object | string $model, array | string | null $actual_fields = UNDEFINED ) : AbstractModel Associate view with a model. Additionally may initialize a controller which would copy fields from the model into the View.

Method Details

__clone() public method

For safety, you can't clone views. Use $view->newInstance instead.
public __clone ( )

_tsBuffer() public method

public _tsBuffer ( $t, $data )

defaultSpot() public method

Normally when you add a view, it's output is placed inside tag of its parent view. You can specify a different tag as 3rd argument for the add() method. If you wish for object to use different tag by default, you can override this method.
public defaultSpot ( ) : string
return string Tag / Spot in $this->owner->template

defaultTemplate() public method

If you return string, object will try to clone specified region off the parent. If you specify array, it will load and parse a separate template. This is overriden by 4th argument in add() method
public defaultTemplate ( ) : string
return string Template definition

getHTML() public method

If argument is passed, JavaScript will be added into on_ready section of your document like when rendered normally. Note that you might require to destroy object if you don't want it's HTML to appear normally.
public getHTML ( boolean $destroy = true, boolean $execute_js = true ) : string
$destroy boolean Destroy object preventing it from rendering
$execute_js boolean Also capture JavaScript chains of object
return string HTML

getJSID() public method

public getJSID ( ) : string
return string

initTemplateTags() public method

This method is called to automatically fill in some of the tags in this view. Normally the call is bassed to $app->setTags(), however you can extend and add more tags to fill.
public initTemplateTags ( )

initializeTemplate() public method

Called automatically during init for template initalization.
public initializeTemplate ( string $template_spot = null, string | array $template_branch = null ) : AbstractView
$template_spot string Where object's output goes
$template_branch string | array Where objects gets it's template
return AbstractView $this

js() public method

Method js() will return jQuery_Chain object which would record all calls to it's non-existant methods and convert them into jQuery call chain. js([action], [other_chain]); Action can represent javascript event, such as "click" or "mouseenter". If you specify action = true, then the event will ALWAYS be executed on pageload. It will also be executed if respective view is being reloaded by js()->reload() (Do not make mistake by specifying "true" instead of true) action = false will still return jQuery chain but will not bind it. You can bind it by passing to a different object's js() call as 2nd argument or output the chain in response to AJAX-ec call by calling execute() method. 1. Calling with arguments: $view->js(); // does nothing $a = $view->js()->hide(); // creates chain for hiding $view but does not bind to event yet. 2. Binding existing chains $img->js('mouseenter', $a); // binds previously defined chain to event on event of $img. Produced code: $('#img_id').click(function(ev){ ev.preventDefault(); $('view1').hide(); }); 3. $button->js('click',$form->js()->submit()); clicking button will result in form submit 4. $view->js(true)->find('.current')->text($text); Will convert calls to jQuery chain into JavaScript string: $('#view').find('.current').text('abc'); // The $text will be json-encoded to avoid JS injection. 5. ON YOUR OWN RISK $view->js(true,'alert(123)'); Will inject javascript un-escaped portion of javascript into chain. If you need to have a custom script then put it into file instead, save into templates/js/myfile.js and then include: $view->js()->_load('myfile'); It's highly suggested to bind your libraries with jQuery namespace by registered them as plugins, this way you can call your function easily: $view->js(true)->_load('myfile')->myplugin('myfunc',array($arg,$arg)); This approach is compatible with jQuery UI Widget factory and will keep your code clean
public js ( string | boolean | null $when = null, array | jQuery_Chain | string $code = null, string $instance = null ) : jQuery_Chain
$when string | boolean | null Event when chain will be executed
$code array | jQuery_Chain | string JavaScript chain(s) or code
$instance string Obsolete
return jQuery_Chain

modelRender() public method

This is used as default values and filled out before the actual render kicks in.
public modelRender ( )

moveJStoParent() public method

Append our chains to owner's chains. JS chains bubble up to app, which plugs them into template. If the object is being "cut" then only relevant chains will be outputed.
public moveJStoParent ( )

on() public method

on() method implements implementation of jQuery on() method. on(event, [selector], [other_chain]) Returned is a javascript chain wich is executed when event is triggered on specified selector (or all of the view if selector is ommitted). Optional other_chain argument can contain one or more chains (in array) which will also be executed. The chain returned by on() will properly select affected element. For example if the following view would contain multiple elements, then only the clicked-one will be hidden. on('click','a')->hide(); Other_chain can also be specified as a Callable. In this case the executable code you have specified here will be called with several arguments: function($js, $data){ $js->hide(); } In this case javascript method is executed on a clicked event but in a more AJAX-way If your method returns a javascript chain, it will be executed instead. You can execute both if you embed $js inside returned chain. The third argument passed to your method contains
public on ( $event, $selector = null, $js = null )
Low level output function which append's to the parent object's template. For normal objects, you simply need to specify a suitable template.
public output ( string $txt )
$txt string HTML chunk

recursiveRender() public method

function recursiveRender(){ $this->add('Text')->set('test'); return parent::recursiveRender(); // will render Text also } When cut_object is specified in the GET arguments, then output of HTML would be limited to object with matching $name or $short_name. This method will be called instead of default render() and it will stop rendering process and output object's HTML once it finds a suitable object. Exception_StopRender is used to terminate rendering process and bubble up to the APP. This exception is not an error.
public recursiveRender ( )

region_render() public method

When "cut"-ing using cut_region we need to output only a specified tag. This method of cutting is mostly un-used now, and should be considered obsolete.
Deprecation: 4.3.1
public region_render ( )

render() public method

For most views, rendering the $this->template would be sufficient. If your view requires to do some heavy-duty work, please be sure to do it inside render() method. This way would save some performance in cases when your object is not being rendered. render method relies on method output(), which appeends HTML chunks to the parent's template.
public render ( )

setModel() public method

Associate view with a model. Additionally may initialize a controller which would copy fields from the model into the View.
public setModel ( object | string $model, array | string | null $actual_fields = UNDEFINED ) : AbstractModel
$model object | string Class without "Model_" prefix or object
$actual_fields array | string | null List of fields in order to populate
return AbstractModel object

Property Details

$_tsBuffer public_oe property

public $_tsBuffer

$auto_track_element public_oe property

public bool $auto_track_element
return boolean

$default_controller public_oe property

automatically.
public string $default_controller
return string

$dq public_oe property

Using dq property looks obsolete, but left for compatibility
See also: self::setModel()
public DB_dsql $dq
return DB_dsql

$js public_oe property

of jQuery_Chains
public $js

$spot public_oe property

$spot defines a place on a parent's template where render() will output() resulting HTML.
See also: output()
See also: render()
public string $spot
return string

$template public_oe property

Example: $view->template->set('title', $my_title); Assuming you have tag in template file associated with this view - will insert text into this tag.
public Template $template
return Template

$template_flush public_oe property

public string $template_flush
return string