I am totaly newbie in PHP frameworks, so sorry for stupit question. I like MVC architecture, but 开发者_运维问答could you please help me to answer question how to design page with more than one blocks of data?
You know, I have quite complex page where you can find for example chart, gainers boxes and other related content. I understand I will create one controller, more data models but what about views?
Is it in habbit to do one view per controller or it is better to have so many views I need there? For example each block on the page will have separate view?
Please help me to understand more to MVC, many thanks for your replies in advance!
Cheers,
Jakub
In my experience to understand MVC frameworks I would suggest picking out one that has a lot of documentations and howtos like codeigniter or cakephp then as you code the framework would probably serve as a guideline on how you would write the page/web application.
I can't speak for all php frameworks, but CakePHP and Lithium provide "elements" which a snippets of code that can be included in your views and layouts. You can pass some of your view data to them. Here's an example of how you might use an element in a Lithium view:
<?php
echo $this->_render('element', 'chart', array(
'title' => 'My Chart',
'data' => array(1, 2, 3, 4, 5),
));
?>
Then, in views/elements/chart.html.php, you can use the data:
<h3><?=$title;?></h3>
<?php foreach($data as $number) : ?>
<?=$number?><br />
<?php endforeach; ?>
精彩评论