Welcome Guest, Not a member yet? Register   Sign In
Using common functionality in all pages (frame) of a CI site
#1

[eluser]TottoBG[/eluser]
Hi from me to all!

I'm getting into CodeIgniter from soon and trying to build a system for a course work for university. I've got into a MVC structure of the system, with controllers that get data from models and display it through views - getting through the CI official documentation and thinking of the structure that will work for me myself. But now I got to sth new that needs different from the MVC connections I've build with CI - and what I've read about CI doesn't seem to help me, so being not able the formulate good enough for a right forums search query I'm asking for help here with this post.

What I need is to include a common dynamic block of functionality in the site frame, in all the pages of it. I only need to get data through model from the DB and display it in a block in a site column - but without initializing it in all the controllers and their different methods that parse a page view.

What are good practices to do such thing in CodeIgniter?

For now I've only created different controllers with their corresponding models and views for the different pages of the site - but all they have no common dynamic functionality, so no need of such a common block till now - every controller with it's method was independent with it's dynamic data of the other controllers and their methods. I've only had a static page frame that all the controller methods parse as a view, just with a dynamic content - and what differs is the content that's being initialized and included into that frame.

Thanks in advance!

Totto
#2

[eluser]TottoBG[/eluser]
Still nothing here. Can anyone give me advise how to structure such common for all the pages of a CI site elements?
#3

[eluser]Dam1an[/eluser]
Hi
If you have some quieries/logic which is common to every function your controllers, you can extend the CI Controller with your own MY_Controller and then use this for your controllers.
You can then put all common login into the constructor there

There are plenty of threads already covering this in the forums, so a search for "MY_Controller" should bring up a few useful threads
#4

[eluser]TottoBG[/eluser]
[quote author="Dam1an" date="1243095513"]Hi
If you have some quieries/logic which is common to every function your controllers, you can extend the CI Controller with your own MY_Controller and then use this for your controllers.
You can then put all common login into the constructor there

There are plenty of threads already covering this in the forums, so a search for "MY_Controller" should bring up a few useful threads[/quote]
Thanks Dam1an,
I'll digg into the mentioned threads here in the forum about extending the Controller. But at least such a scheme should give a result. The different pieces of common logic (blocks with some data) may be loaded by methods of the My_Controller class, called by it's constructor - so they would be initialized for the siteframe view, that all the other controllers fill.

Thanks again for the direction!




Theme © iAndrew 2016 - Forum software by © MyBB