CodeIgniter Forums

Full Version: Best practise advice needed - where to put small PHP widgets within the app?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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.

El Forum

[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.

El Forum

[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]

El Forum

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

El Forum

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