Question: Quick question about general MVC design principle in PHP, using CodeIgniter or Kohana (I'm actually using Kohana).

I'm new to MVC and don't want to get this wrong... so I'm wondering if i have tables:

```
categories, pages, notes

```

I create a separate controller and view for each one...? So people can go to 

```
/category/#
/page/#
/note/#

```

But then lets say I want to also be able to display multiple notes per page, it would be bad to call the note view in a loop from the page view. So should I create some kind of a function that draws the notes and pass variables to that function from the note view and from a loop in the page view? Would this be the best way to go about it, if not how else should I do it...?

Thanks,

Serhiy

Answer: 
Yes, instead of just passing 1 entity (category, page, note) to your view, pass a list of entities. With a loop inside the view, you can display the whole list.
That view may call another one (or a function) that know how to display one entry.
In CodeIgniter I create a separate helper file where I put functions that return the markup for UI elements that may need to be included multiple times in the one view.

In your example, I would create a function to return the markup for a note.

**application/helpers/view\_helper.php**

```
function note($note)
{
    return '<div class="note">' .
        '<h2>' . $note->title . '</h2>' .
        '<p>' . $note->contents . '</p></div>';
}

```

I would normally auto-load this helper file. And then in the view I would do something like this.

```
echo note($note);

```

For a list of notes in a view, I would iterate the list calling this function.

```
<div class="note-list">
<?php foreach ($notes as $note) : ?>
    <?php echo note($note); ?>
<?php endforeach; ?>
</div>

```

I found that including a view many times in another view was slow. Thats why I did it this way.

**Edit**

I just dug into the CodeIgniter Loader class and sure enough a PHP include is being done every time you call

```
$this->load->view('view_name');

```

This means that if you use this method to display a list of 20 notes, you're going to be doing 20 separate includes.