Welcome Guest, Not a member yet? Register   Sign In
How to suport indipendent view fragments in CI
#1

Say i  have  a view (main view), which corresponds with a controller (Main controller) northing fancy here its the normal ci way.

but what if on that main view, i had a list, sidebar nav, and maybe a footer, and i wanted to have each of these fragments to have their own independent controller. in that when the main controller is run, it calls the controllers for all these different fragments and load them.

Or if any of these fragments' controller is called say by using JavaScript, this single fragment can be updated independently.

The benefit is, i can re-use this controller and its fragment on other pages where that they are needed to display data same data.

How can i archive this with CI?
From the ghetto to Information Systems Engineer,
Reply
#2

(06-23-2016, 07:02 AM)katwekibs Wrote: Say i  have  a view (main view), which corresponds with a controller (Main controller) northing fancy here its the normal ci way.

but what if on that main view, i had a list, sidebar nav, and maybe a footer, and i wanted to have each of these fragments to have their own independent controller. in that when the main controller is run, it calls the controllers for all these different fragments and load them.

Or if any of these fragments' controller is called say by using JavaScript, this single fragment can be updated independently.

The benefit is, i can re-use this controller and its fragment on other pages where that they are needed to display data same data.

How can i archive this with CI?

There are several ways to achieve this. I have achieved this exact same thing by extending my base loader controller and having the function to create a view pass in data from the other 'fragments' that are required.

In the loader controller, you can tell it to load the entire page if it's not an ajax call or just the main view if ajax is called.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB