Reputation: 1
I have got a menu class:
addMenuItem ($parent)
modifyLinkTarget ($item)
etc. Now I will show it with a show()
method, which should produces HTML output. But its not a good way, because what if I have several templates while it produces one HTML. CSS wont help standalone :) so how to display it not to hurt MVC and being flexible?
Upvotes: 0
Views: 592
Reputation: 4199
The menu class contains your items, links etc. and is your model. As you correctly said, the model does not output anything, it is the task of the view. So you have to pass the model (menu class object) to your view, where you can output it. For this, your menu class might need some additional methods like getAllMenuItems(int $parentItem) or something like that. In your view, you can do something like this:
<ul>
<?php foreach($menuClass->getAllMenuItems(2) as $item) { ?>
<li>$item['text']</li>
<?php } ?>
</ul>
As you can see, you might have to extend your menu model with a menuItem class, to follow the OOP way. Your menu class organizes several menuItem objects.
Overall, you have to following situation:
header('some html utf8 http header stuff');
echo viewObject->generateHTML('template.tpl', $contentData, $menuObject);
Upvotes: 2