• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you work with Views within your Controller?

So I've been tinkering with CI, and I'm pretty sure I want to use it for my next project, but I've been putting together a demo site, and I'm a bit uncomfortable with how I find myself repeating my view code in my controllers.

I've created a few views out of some content that I intend to repeat a bit: 'header', 'nav', 'footer', the content was mainly broken up for organizational purposes.

I then surround the view that I'm working on in my controller, like so:

$this->load->view('register', $data);

So, I guess this is a two part question:

1) I'm typing this stuff in *every* controller I make, and it just feels like there might be a better solution for this rather than copy and pasting the general views on every controller that I make.

2) With regards to these repetitive pages, if I need to run general queries or assignments to pass in generic data to the view, that will *also* be copied into every view. (example: passing in some session data into the nav view)

I read the wiki about using multiple views on the same page, and while it told you *how*, it didn't really jump at talking about if there was a better perceived way about handling this kind of stuff.

Any advice/comments is appreciated. Smile

Read this and MY_Controller in the User Guide.
CodeIgniter Base Classes Keeping it DRY


Check out my posting in this thread http://ellislab.com/forums/viewthread/173268/

In short, I let my template load all of the redundant stuff - header, navigation, footer, etc... I pass a value from the controller to the template that says what the content should be and the view loads the main content view.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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