How is my approach to reuse view logic in my project?

ε祈祈猫儿з 提交于 2019-12-13 00:47:58

问题


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 -

  1. Search->Class listings - list of classes displayed in search results.
  2. Student room->Class listings - List of classes a student has purchased

  3. Search->Class Details - Details page of a class in search module

  4. Student room->Class Details - Details page of a class in Student room

and similarly for packs -

  1. Search->Pack listings - list of packs displayed in search results.
  2. Student room->Pack listings - List of packs a student has purchased.

  3. Search->Pack Details - Details page of a pack in search module

  4. 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 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

来源:https://stackoverflow.com/questions/3475935/how-is-my-approach-to-reuse-view-logic-in-my-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!