this module is part of Yima Application Framework
Widget is a class that implement minimal interface WidgetInterface
interface WidgetInterface
{
/**
* Render widget as string output
*
* @return string
*/
public function render();
}
Widgets stored in widget plugin manager (serviceLocator for widgets).
stored with serviceManager key yimaWidgetator.WidgetManager
and build as factory service.
return array(
/**
* Register Widgets in WidgetManager
*
* each widget must instance of WidgetInterface
*/
'yima_widgetator' => [
// This is configurable service manager config
'services' => [
'invokables' => [
# 'widgetName' => 'Widget\Class',
],
'initializers' => [
// DB: Using Global db Adapter on each services Implemented AdapterAwareInterface
function ($instance, $sl) {
if ($instance instanceof \Zend\Db\Adapter\AdapterAwareInterface) {
$sm = $sl->getServiceLocator();
$instance->setDbAdapter(
$sm->get('Zend\Db\Adapter\Adapter')
);
}
}
],
],
'widgets' => [
/** @see RegionBoxContainer */
'region_box' => [
# // $priority default is start with 0
# $priority => 'WidgetName',
# $priority => [
# 'widget' => 'WidgetName'
# 'params' => [
# 'with_construct_param' => 'param_value'
# ]
# ],
],
],
],
In Controller with controller helper:
$this->layout()->side_bar = $this->widget('widgetName')->render();
In View Script:
<div class="container">
<p><?php echo $this->widget('widgetName')->render();?></p>
</div>
ajax widget loading need some js resources you can find in www
folder of module,
you can put file anywhere you want and edit config\module.config.php
.
return array(
/**
* Libraries that used in Ajax Loading of widgets.
* @see \yimaJquery\View\Helper\WidgetAjaxy
*/
'static_uri_helper' => array(
'Yima.Widgetator.JS.Jquery.Ajaxq' => '$basepath/js/yima-widgetator/jquery.ajaxq.min.js',
'Yima.Widgetator.JS.Jquery.Json' => '$basepath/js/yima-widgetator/jquery.json.min.js',
),
for more info around static_uri_helper
see yimaStaticUriHelper
In View Script:
<div class="container">
<p id="container_id">
<?php
echo $this->widgetAjaxy('widgetName', // widget name
array('option' => 'value'), // options
'container_id', // id of dom element
'function callback(response)' // callback after loading widget
);
?>
</p>
</div>
I`m working to improve ajax loading of widgets.
We have some Abstract class for widgets called: AbstractWidget and AbstractMvcWidget. (take a look)
Example Widgets and AbstractClasses will be added.
Composer installation:
require rayamedia/yima-widgetator
in your composer.json
Or clone to modules folder
Enable module in application config
To report bugs or request features, please visit the Issue Tracker.
Please feel free to contribute with new issues, requests and code fixes or new features.