CodeIgniter Forums
How to implement reusable widgets? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How to implement reusable widgets? (/showthread.php?tid=65452)



How to implement reusable widgets? - groovebird - 06-13-2016

Hi,

i want to display the product top ten on several pages. What is the best way to do that? The data are stored in a database. Should i create a function in my_controller or is there another way (Library)? There is not only a product top ten, there are also other cases (eg. last viewed products).


RE: How to implement reusable widgets? - ivantcholakov - 06-13-2016

(06-13-2016, 01:03 PM)groovebird Wrote: Hi,

i want to display the product top ten on several pages. What is the best way to do that? The data are stored in a database. Should i create a function in my_controller or is there another way (Library)? There is not only a product top ten, there are also other cases (eg. last viewed products).

I am a fan of this concept, but achieving it in CodeIgniter 3 requires third-party stuff to be installed and tested. The bare minimum is https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc

I use my MIT-licensed CI-based platform with HMVC that adds some comfort in creating visual widgets https://github.com/ivantcholakov/starter-public-edition-4
See this sample page, the section "Widgets" http://iridadesign.com/starter-public-edition-4/www/playground/twig-parser

Actually, right now am am doing such a work, see the attached image. The visual theme is taken from here https://github.com/dragdropsite/mPurpose


RE: How to implement reusable widgets? - groovebird - 06-13-2016

Hi,

this sounds good but is it possible to implement this in an existing application?


RE: How to implement reusable widgets? - ivantcholakov - 06-13-2016

Install HMVC by wiredesignz, version 5.5 claims to be compatible with CI3. Then within your view you can make something like this:

Code:
foreach ($items as $item) {
    echo Modules::run('product_item_widget/index', $item);
}