Welcome Guest, Not a member yet? Register   Sign In
Best MVC site structure?
#1

[eluser]N.S.G.[/eluser]
Hi everyone.

I'm new to CI. Also new to the whole MVC programming for that matter.

I've read some tutorials and I think I pretty much understand the basics, so now I want to start with my own project.

Now even before I can start there's something I run into. Probably an easy question for you guys:

Suppose my project is an online community with a login section, a user page and a forum. Basically that would mean (correct me if I'm wrong) I would make three controllers that be called using mysite.com/login, mysite.com/user and mysite.com/forums. Every controller eventually calls a view. Now the thing is, my site of course has a layout that is pretty much the same no matter which page is shown. My question: where do I put the html for that? It seams stupid to put the same html in each view file, right?

Please help Smile Much appreciated!
#2

[eluser]bretticus[/eluser]
[quote author="JurgenCreative" date="1262818494"]
Suppose my project is an online community with a login section, a user page and a forum. Basically that would mean (correct me if I'm wrong) I would make three controllers that be called using mysite.com/login, mysite.com/user and mysite.com/forums.
[/quote]
This is really up to you. However I see login as a function of the user controller /user/login. If you want to get the aesthetics of /login, you can perform that using routes.
[quote author="JurgenCreative" date="1262818494"]
Every controller eventually calls a view. Now the thing is, my site of course has a layout that is pretty much the same no matter which page is shown. My question: where do I put the html for that? It seams stupid to put the same html in each view file, right?
[/quote]
There are several ways to do this. One method (nesting views also covered in the link below) is to create one view that is always loaded by every controller function and has the various sections of your HTML layout:

header
head
contents
footer

In this example, header, head, and footer are views called via include or CI load view method. The contents area is called by passing a variable to this view that is the path (or part of it.) The "one" view can then dynamically load the content.

A more common approach is to simply call multiple views from your controller.

Here is an example.

Of course there are many other methods to implement layout in this fashion. Be sure to google and check back here for others that will undoubtedly post those methods.
#3

[eluser]N.S.G.[/eluser]
Thanks that was very helpfull! It never occured to me that I could call the view command more than once Tongue So stupid. I'll give it a try.




Theme © iAndrew 2016 - Forum software by © MyBB