Welcome Guest, Not a member yet? Register   Sign In
Design question - One page for the site = one big controller ?
#1

[eluser]duartix[/eluser]
I'm facing a design question. My application (a small project so far) will have this kind of design

HEADER

Menu Major
Option 1
Option 2
Option 3 Content

Login Panel
Panel
FOOTER

My home controller is doing all the work of loading the header, the menu on the left, the login information panel and the footer. All these are different views and at the moment, home loads them all.

Most of the data (according to the menu options) will be show on "Major Content Panel", which will be a big panel inside the frame.

The design choice that I'm facing here is: should I make new controllers for Menu Options 1,2 & 3? Or should I keep just the home controller since it already has the code and data necessary to load everything around Major Content Panel?

#2

[eluser]RobertSF[/eluser]
Here's how I did it. I also have a header.php and a footer.php in my view folder, but I have the content view load them. I don't load them from the controller. I only load the content view from the controller.

In my controller, I have:
Code:
$this->load->view('content_view');

Then, in my content_view.php file, I have:
Code:
<?php $this->load->view('header'); ?>

<div id='content'>

<h1>Title of Content</h1>

&lt;form method='post' acti&gt;
  (all the form fields)
&lt;/form&gt;

</div>&lt;!-- content --&gt;

&lt;?php $this->load->view('footer'); ?&gt;

So, for the controllers themselves, the best advice I think I got was to make one controller per related purpose. For example, for user authentication, instead of having three controllers for login, register new user, and retrieve lost password, have one controller for users with functions user/login, user/register, user/get_password.
#3

[eluser]duartix[/eluser]
Yes, that's a possible way do it.

But as I stated, in my case there is a strong dependency on session data (as an example the LOGIN panel needs a lot of session info in order to know what information to show on that panel - heck, the panels (views) that load are dependent on that data), so it makes more sense to be the controller to deal with it and not the views.

My question here is how far do I take it... one controller for all the menu options, or one for each...



#4

[eluser]RobertSF[/eluser]
In that case, one controller for all menu options, especially if the project remains small and contained.

One thing you could look into is inheriting from your controller instead of the CI controller. You first setup your one controller with the code that will be common for all other controllers. Let's say you call it My_Controller.

Then you create controllers for each menu option, but you extend My_Controller, not CI_Controller. Like this.
Code:
class  Whatever extends My_Controller {

Of course, you could leave that for a project rewrite, and just finish the project using one controller for now. Smile




Theme © iAndrew 2016 - Forum software by © MyBB