Aim
To implement a proper and efficient view architecture for my project (with maximum reuse of repeated units)
About my project
My project involves classes taken by tutors and packs published by tutors. No framework has been used but object orientation and class hierarchies are present for model, controller part.
I have the following modules -
- Search->Class listings - list of classes displayed in search results.
Student room->Class listings - List of classes a student has purchased
Search->Class Details - Details page of a class in search module
- Student room->Class Details - Details page of a class in Student room
and similarly for packs -
- Search->Pack listings - list of packs displayed in search results.
Student room->Pack listings - List of packs a student has purchased.
Search->Pack Details - Details page of a pack in search module
- Student room->Pack Details - Details page of a pack in Student room.
My current plan
I am planning to have classes like these:-
Class Name Contents
commonListingDisplay paginationHtml()
smallRatingHtml()
commonDetailsDisplay commentsHtml()
largeRatingHtml()
commonClassPackListingDisplay extends commonListingDisplay
abbreviatedDetailsHtml()
(abbreviated class/pack
details html (class/pack details
ending with ... and a link to the
Class/pack details page).
commonClassPackDetailsDisplay extends commonDetailsDisplay
currently empty
commonClassDisplay classDateTimeHtml()
classReminderHtml()
classDetails extends commonClassPackDetailsDisplay,commonClassDisplay
- I know PHP does not support multiple inheritance but that can be faked as answered in http://stackoverflow.com/questions/356128/can-i-extend-a-class-using-more-than-1-class-in-php
Now taking the example of a module - While in Search->Class details- - From the search_class_details.controller.php file, initiate an object of class classDetails, so all the reusable functions are accessible. - Pass all the variables and the classDetails object to a class_details.view.php (which is the view file of class_details module). The file will look something like:-
<div class="class_details">
<h2><?php echo $className ?></h2>
<div><?php echo $classDetails ?></div>
<?php $classDetailsObj->largeRatingHtml($ratingValue) ?>
<?php $classDetailsObj->commentsHtml($commentsArray) ?>
</div>
How does the approach look like? Suggestions from experienced people wanted.
Thanks