Welcome Guest, Not a member yet? Register   Sign In
Having some issues with my CI powered app. (Showing dynamic sidebar on every single page)
#1

[eluser]loathsome[/eluser]
Hi there,

Recently I've been exploring CI, and so far I simply love it!

Anyway, I have a small problem now. I'm developing an application, and this app uses a sidebar. I load the sidebar view in the header, and the header in the index-file.

The sidebar contains data fetched from a database, and this fetching is done through the index controller (called "Main").

So far so god!

I just created a new controller for administration, then it struck me; Do I have to fetch the sidebar data for EVERY single controller I have? Because the sidebar is going to be globally displayed, on every single page.

Many thanks for your help!

Best,
loathsome
#2

[eluser]Chicken's Egg[/eluser]
Quote:Do I have to fetch the sidebar data for EVERY single controller I have?
Yes - as far as I do - you have. Personally I create a base_controller which extends the controller. Then I build the normal controller I need which extends the base_controller. The base_controller can take care af the sidebar and I don't have to think about copy pasting the code all the time.
#3

[eluser]loathsome[/eluser]
Thanks for the idea about the "base_controller". Though, I still find this a little troublesome, but if that's the only way, well - that's the only way.

Unless somebody else knows anything.

Thank you :-) (edit: woah, what an ugly smiley!)
#4

[eluser]sophistry[/eluser]
welcome loathsome...

you'd be better off putting some details in your post title next time. posts like these tend to get lost in the shuffle.

you should look into "partials", "modules", or "blocks" on the forums and the wiki. there are several ways of structuring getting/building the sidebar only once and then stuffing it in place.

the best way is what ever you are comfortable with; however, i'd suggest finding a caching library and simply caching the sidebar view (you need 3rd party code here because CI does not support view caches, only full page caches).

you could also hack up a kind of cache by using the sessions library (may i suggest using the db version rather than the default that stores data directly in the cookie). store your sidebar in the session data.

just implementing caching does not help with the actual streamlining of the code architecture but it will speed things up. organizing code blocks and streamlining their output can be done with Modular Extensions - a drop-in set up that allows you to nest controller output.

let us know how it goes.
#5

[eluser]loathsome[/eluser]
Thanks for your great reply, sophistry! Though, I didn't find anything useful searching the wiki for the keywords you provided with. Could you please be a little more specific, or come up with a small example?

As far as the cache tip goes, that's not a solution I'm interested in doing right now.

I greatly appreciate your help!

Thanks.
#6

[eluser]sophistry[/eluser]
no, i'm feeling grouchy so i won't do the searching for you. ;-)

search the forum for Modular Extensions if you don't want to use the (shortcut) cache solution to the dynamically-generated sidebar issue.

you would also do well to follow wiredesignz in general to learn about CI. click through to his member page and look at his posts and threads to see how an advanced coder with good knowledge of CI really works.
#7

[eluser]loathsome[/eluser]
Thanks again, but I have to admit I fail to see what I'm supposed to do. Is this what you're talking about?

I'm sorry if I'm acting stupid, I just started working with CI yesterday!
#8

[eluser]sophistry[/eluser]
no. similar but not the same. i think i might be confusing you with high-level stuff before the basic CI stuff is solid. :-(

no problem acting stupid! as long as you don't take it too seriously... :-)

modular extensions v 4.2 thread.

it occurred to me that you might be asking a more basic question... is your question "how do i include one view inside another?"?

also, if you have just started with CI, then don't go jumping into Modular Extensions right away - just make a helper to load the dynamic sidebar and call it in wherever you need it. you say you don't want a cache so i gather you want a single point to "include" the sidebar view?
#9

[eluser]loathsome[/eluser]
Now there you go, using a helper is a great idea and that worked flawlessly! Thanks a lot!




Theme © iAndrew 2016 - Forum software by © MyBB