• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best Strategy for Dynamic Header and Footer sections?

#11
[eluser]majidmx[/eluser]
Hey,
to keep the view apart from code, do it in a library or plugin.

#12
[eluser]Rey Philip Regis[/eluser]
Quote:Right now, the dynamic information determines whether the person is logged in or not (checks a session variable) and changes the top menu based on that information.

For now, I just put the coding in the header file, I may need to do something different if there is more information I need to process with it.

Put your code in the header file. Then create a library, the library that you will create should be implementing a like a factory pattern. You will have a base class, then two child classes for logged in and logged out class. Then You place the base class in you header file, then pass the dynamic information in your base class, there it will determine whether the person is logged in or not and then instatiating the correct child class. Is it applicable or am I not getting the right scenario?

Good day.

#13
[eluser]Thorpe Obazee[/eluser]
[quote author="Rey Philip Regis" date="1228289157"]
Quote:Right now, the dynamic information determines whether the person is logged in or not (checks a session variable) and changes the top menu based on that information.

For now, I just put the coding in the header file, I may need to do something different if there is more information I need to process with it.

Put your code in the header file. Then create a library, the library that you will create should be implementing a like a factory pattern. You will have a base class, then two child classes for logged in and logged out class. Then You place the base class in you header file, then pass the dynamic information in your base class, there it will determine whether the person is logged in or not and then instatiating the correct child class. Is it applicable or am I not getting the right scenario?

Good day.[/quote]

That's basically what I do.

Create a class. Then class does what I want it to do... where to output data, or check for anything... No add code will be added to your methods. Just load it via the 'view'.

#14
[eluser]Thorpe Obazee[/eluser]
There's also this:

http://ellislab.com/forums/viewreply/458770/

#15
[eluser]fchristant[/eluser]
My strategy for this (having common, dynamic data available in each view):

- create a base controller class
- make sure all your controllers extend the base controller class
- in the base controller class, create a public object or array, let's say $data
- in the constructor of the base controller, fill $data with whatever you like

Now, from any view (including a header) you can access this variable using:

$this->data['your property']

I like this method because in your actual controllers you need no additional lines of code. Likewise, your views do not need to load other views, or worse, libraries.

Not saying this is perfect or anything, it's just that it worked really well for me.

Bonus tip: Having a base controller is useful for other things as well. For example, I can dynamically load javascript libraries this way, and my header gets updated automatically to do that.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.