© 2015 X2Engine Inc.

Difference between revisions of "Widgets"

From X2Engine
Jump to: navigation, search
(Created page with "= Introduction = One immediately recognizable features of the web application is the diversity of widgets on the right-hand side of the window, each containing some user input...")
 
Line 1: Line 1:
 +
[[Category:Development]]
 +
 
= Introduction =
 
= Introduction =
 
One immediately recognizable features of the web application is the diversity of widgets on the right-hand side of the window, each containing some user input and/or output. Each of those widgets is generated by a class that extends X2Widget, which can be found in <tt>protected/components</tt>. The widgets are loaded into the controller by the [http://doc.x2engine.com/class-x2base.html#_filterSetPortlets setPortlets] filter (and inherited by all subclasses of [[x2doc:x2base]]).
 
One immediately recognizable features of the web application is the diversity of widgets on the right-hand side of the window, each containing some user input and/or output. Each of those widgets is generated by a class that extends X2Widget, which can be found in <tt>protected/components</tt>. The widgets are loaded into the controller by the [http://doc.x2engine.com/class-x2base.html#_filterSetPortlets setPortlets] filter (and inherited by all subclasses of [[x2doc:x2base]]).

Revision as of 21:59, 17 September 2012


Introduction

One immediately recognizable features of the web application is the diversity of widgets on the right-hand side of the window, each containing some user input and/or output. Each of those widgets is generated by a class that extends X2Widget, which can be found in protected/components. The widgets are loaded into the controller by the setPortlets filter (and inherited by all subclasses of x2doc:x2base).

Creating a widget

The first step to creating a new widget is to make a new PHP class that extends x2doc:X2Widget, name the file after the class, and to place the widget in the protected/components directory. Note the inheritance of properties from yii:CWidget, the parent class of X2Widget. A complete widget should contain, at minimum, an override of the CWidget::run() method that constructs the markup associated with that widget.

Adding the widget to the registry

Widgets loaded by filterSetPortlets are loaded are contained in the application configuration parameter "registeredWidgets" (in protected/config/main.php), in the format "ClassName" => "Widget Title":

		'registeredWidgets'=>array(
			'TimeZone' => 'Time Zone',
			'MessageBox'=>'Message Board',
			'QuickContact'=>'Quick Contact',
			'GoogleMaps'=>'Google Map',
			'TwitterFeed'=>'Twitter Feed',
			'ChatBox'=>'Chat',
			'NoteBox'=>'Note Pad',
			'ActionMenu'=>'My Actions',
			'TagCloud'=>'Tag Cloud',
			'OnlineUsers'=>'Active Users',
			'MediaBox' => 'Media',
			'DocViewer' => 'Doc Viewer',
			'TopSites' => 'Top Sites',
		),

Widget views

All widgets will by default render views named in protected/components/views. Thus, to build the display markup for a widget, it is not necessary to generate it all within the widget class itself; the markup associated with a widget can be placed within a view file in that directory and then used with a call to renderPartial similar to how one would do so in a controller.