CodeIgniter Forums
Best practise advice needed - where to put small PHP widgets within the app? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Best practise advice needed - where to put small PHP widgets within the app? (/showthread.php?tid=25977)



Best practise advice needed - where to put small PHP widgets within the app? - El Forum - 01-02-2010

[eluser]Peter Lachky[/eluser]
Hi guys,

as I am still new to CI and some areas are not quite clear to me I would like to ask you for an advice.

I am developing this application which, in browser, has the main content area and the right and left sidebars with some widgets, eg: search button, ads, list of categories, list of tags, current weather, etc...

My question is: Where do I put these widgets? Those are rather small pieces of code and I would like to keep them in separate files. However, these can not be views as some of them need to access the database. What is the best practise to achieve something like this?

Thanks for your time.


Best practise advice needed - where to put small PHP widgets within the app? - El Forum - 01-02-2010

[eluser]Colin Williams[/eluser]
These widgets, in my app, would exist in the main template view. If they require dynamic data, this would be supplied via $this->load->vars() likely in the controller constructor.


Best practise advice needed - where to put small PHP widgets within the app? - El Forum - 01-03-2010

[eluser]jedd[/eluser]
[quote author="Peter Lachky" date="1262508344"]
My question is: Where do I put these widgets? Those are rather small pieces of code and I would like to keep them in separate files. However, these can not be views as some of them need to access the database. What is the best practise to achieve something like this?
[/quote]

View partials can still be given data from the database, so this means that these widgets (or view partials) can still be views (ie. reside under the views directory somewhere).

Have a read of these two threads - they might provide a bit more insight into the general pattern.

[url="http://ellislab.com/forums/viewthread/109698/"]http://ellislab.com/forums/viewthread/109698/[/url]
[url="http://ellislab.com/forums/viewthread/110969/"]http://ellislab.com/forums/viewthread/110969/[/url]


Best practise advice needed - where to put small PHP widgets within the app? - El Forum - 01-03-2010

[eluser]wiredesignz[/eluser]
You might find my Widget plugin useful also. See my signature for the link.


Best practise advice needed - where to put small PHP widgets within the app? - El Forum - 01-03-2010

[eluser]umefarooq[/eluser]
@wiredesignz widget plugin is really nice and easy to use just like your controller give it try.