Welcome Guest, Not a member yet? Register   Sign In
is it possible to send specific data to all my views without doing it in every controller?
#1

[eluser]brainer[/eluser]
I have a huge site, where i want to send a random quote taken from the database to every page.

I'm just wondering if there is some way to make every view recieve data without me needing to replicate the model call in every controller and then pass the information into the view.
#2

[eluser]rogierb[/eluser]
yeah you can. Extend the controller


;-)
#3

[eluser]brainer[/eluser]
thanks! ill give it a go
#4

[eluser]jedd[/eluser]
[quote author="linasaur" date="1255716034"]
I'm just wondering if there is some way to make every view recieve data without me needing to replicate ...
[/quote]

If only this kind of thing was [url="http://codeigniter.com/wiki/FAQ/"]documented in the FAQ in the wiki[/url].
#5

[eluser]brainer[/eluser]
[quote author="jedd" date="1255718304"]
If only this kind of thing was [url="http://codeigniter.com/wiki/FAQ/"]documented in the FAQ in the wiki[/url].[/quote]

....didn't know what i was looking for.

anyway, thanks rogierb, i ended up using instructions i found here:
http://www.lizjamieson.co.uk/2008/12/03/...igniter-6/
#6

[eluser]BrianDHall[/eluser]
Wow, just edited the wiki for the first time - damn that's cool.

Added my take, which is to use a class variable of $this->data initialized in the constructor - mainly useful for one-controller apps or for data that only needs to be added to a single controller. This can of course be used with an extention to the base controller class as well.
#7

[eluser]jedd[/eluser]
Hey - there's no [url="http://codeigniter.com/wiki/Class_variable_declared_in_constructor_-_BrianDHall's_take/"]http://codeigniter.com/wiki/Class_variable_declared_in_constructor_-_BrianDHall's_take/[/url] page! I feel .. cheated! Wink

Brian - perhaps you could elucidate at more length in that page (or rename it slightly so it fits the format better) - you can copy the contents of my page (go to edit my comparable take there, cut-n-paste the edit-window contents, discard my page edit, paste it back into your take page) and I can clean up the category stuff later (the CI wiki category handling is quite the mess).

And yes, the wiki is pretty cool, despite its shortcomings.




Theme © iAndrew 2016 - Forum software by © MyBB