Welcome Guest, Not a member yet? Register   Sign In
Organising a web page
#1

[eluser]Bisquite[/eluser]
I am currently getting to grips with the MVC framework and have some questions around the best way to structure my models, views and controllers.
I am a traditional web developer, writing whole web pages with HTML and php.

I want to have a website homepage with a header and a footer, and in the main body of the page would be a sidebar and maybe a larger news section. The sidebar would contain 3 tables of information dynamically pulled from the database (3 separate database queries), and similarly the news section would display a large article and the 3 most recent articles below it, slightly smaller.

Given this setup, what kind of arrangement of MVC elements should I be aiming for? Is it one view for each of the header, footer, sidebar and news section? Or is it one view for each of the 3 sidebar elements, 1 view for the large news section and another for the smaller news articles?
And also, does each view have a controller?

Any links to good examples would be greatly appreciated!

Thanks for any assistance.
b/
#2

[eluser]InsiteFX[/eluser]
You can break up your web page into view files and in the main web page you load each view that you need.

Controller:
Code:
$data = array(
    'title',
);

$this->load->vars($data);    // NOTE: This makes the $data global to all of the views.
$this->load->view('main_view_file_here');

main_view_file_here:
Code:
<?php $this->load->view('header');

<?php $this->load->view('sidebar');
<?php $this->load->view('content');

<?php $this->load->view('footer');

Each view file would be in the ./application/views directory, but you can also have sub-directories.

Should get you started.
#3

[eluser]Bisquite[/eluser]
Thanks for the reply. So am I right in taking from this that you would adopt a set of nested views? i.e similarly to the main view, my sidebar view would then call 3 sub-views corresponding to the 3 sets of dynamic data I wish to extract from the database?
#4

[eluser]InsiteFX[/eluser]
yes, but you could do it in one sidebar view, by just passing the data in the $data array.




Theme © iAndrew 2016 - Forum software by © MyBB