Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 650269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:02:04+00:00 2026-05-13T22:02:04+00:00

I’m creating a library of display objects for our application. They render the html

  • 0

I’m creating a library of display objects for our application. They render the html of a lot of the common objects (users, conversations, messages, etc) in various views. By views I mean the object can spit back different ‘zoom levels’ of itself with different markup.

Some display objects contain other display objects to render eg. a user list object renders user objects in a certain view (this particular view spits them back in list items so they fit into the list)

I’m trying to move these into the proper way of doing things in ZF, but I can’t decide if these should all be view helpers, or if they are all view scripts/partials.

Just making them view scripts and rendering them with ->render() seems a little dirty because any information or parameters I want to pass to them has to be assigned to the view object.

Partials seem a little more correct, except not sure if its proper to be doing display logic in these (if ‘showNotificationStatus’ is passed as a parameter, render this span). Or if its kosher for partials to render other partials (a user list rendering the user object).

View helpers seem like possibly the right way to do it, but I don’t know if that is overusing view helpers. Each object could be a view helper and accept a objectview parameter so it knew what zoom level/container to render itself in, or each objectview could even be its own helper (so there’s no big switch statement inside an object). One nice thing about the views is you can pass parameters and it still has access to the view context if you need something from that level.

Most of these are going to be accepting models, with a few requiring some extra parameters to know what to do (eg. showNotificationStatus from above). What’s the proper tool for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:02:04+00:00Added an answer on May 13, 2026 at 10:02 pm

    One of the core ideas of partials is that they’re meant to be as re-usable as possible – hence why they have their own variable scope. I like to use partials as fairly dumb containers for small bits of HTML. No major logic other than a few if() or foreach() statements.

    If I need serious logic – I use a helper. Helpers should be responsible for dealing with logic and calling render methods. I know in the Rails world, helpers tend to encapsulate little bits of logic, like handling the construction of links or image tags. This is great, but I don’t think there’s any harm in making them more complex in ZF. I essentially use them to translate my business objects into views.

    I think the best way to use both partials and helpers is have helpers set up the data, then pass it into partials. This way your HTML stays very easy to maintain (and I suspect that every time someone types echo "<a href='". $my_link . '"/>" a kitten dies somewhere).

    EDIT (to elaborate):

    The thing to remember about helpers is that they can be treated like normal classes, use a constructor with arguments and have private members. So when you instantiate a helper, you can a business object, and then have multiple methods that render HTML (via partials).

    So in my view:

    <?php $helper = $this->_helper->MyUserHelper($users); ?>
    <ul>
      <?php $helper->user_list(); ?>
    </ul> 
    

    Here, the user_list() method returns a collection of <li> elements with all the proper data in them.

    My helper might looks like this:

    class MyWidgetHelper 
    {
      private $_widget;   
    
      public function __construct($users)
      {
         $this->_users = $users;
      }
    
      public function user_list()
      {
         // do any necessary logic here
         // then return the html that gets rendered. 
         // you can call a partial from here, and it just returns an HTML string.
         return $this->_view->partial('partials/_user_item.phtml', array('users' => $users)
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 417k
  • Answers 417k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There's a subtle difference between a using declaration (using A::f)… May 15, 2026 at 9:48 am
  • Editorial Team
    Editorial Team added an answer No. You generally can't affect phone-wide features like that, nor… May 15, 2026 at 9:48 am
  • Editorial Team
    Editorial Team added an answer From what I gathere you are looking something along the… May 15, 2026 at 9:48 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.