I have searched for this topic here and Google but I only found the solutions with PHP frameworks (for example, YII and Laravel)
I am developing a simple CMS and I would like to add widget system just like WordPress ( Recent Comments, Categories widgets )
- List available widgets.
- Users can active the widgets and use them in sidebar.
My steps:
1. First at all, I already made an admin tool as the screenshot blow ( jQuery UI sortable works fine)
Here is my php code:
$available_widgets = array(
0 => array(
'id' => 'recent-post',
'title' => 'Latest Pots',
'option' => array( 'display_count' => 5, 'multi_widget' => 0)
),
1 => array(
'id' => 'recent-comment',
'title' => 'Recent Commets',
'option' => array( 'display_count' => 5, 'multi_widget' => 0)
),
2 => array(
'id' => 'text-box',
'title' => 'Text Box',
'option' => array('multi_widget' => 1)
)
);
View
foreach ( $available_widgets AS $available_widget ) {
if ( $available_widget['option']['multi_widget'] == 0 ) {
echo '<li class="widget-box widget-single" data-widget-id="' . $available_widget['id'] . '" ><div class="widget-handle">' . $available_widget['title'] . '</div></li>';
}
else {
echo '<li class="widget-box widget-multiple" data-widget-id="' . $available_widget['id'] . '" ><div class="widget-handle">' . $available_widget['title'] . '</div></li>';
}
}
But I still no idea about the next step, any idea will be grateful. Thanks.
Update:
For my step 2 I made a simple EventDispatcher, I put the link here if someone else needs it. https://github.com/terrylinooo/PHP-EventDispatcher