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

  • SEARCH
  • Home
  • 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 8280063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:32:10+00:00 2026-06-08T09:32:10+00:00

I am currently working on a Zend Framework project whereby the end result of

  • 0

I am currently working on a Zend Framework project whereby the end result of the users journey through the application presents them with a large table containing their results. This table can contain varying numbers of rows, most of which are generated as the results of calculations. So far, so good.

The first; albeit minor hurdle, is that the table needs to be presented horizontally. That is, the headings are in column 1 and each additional column represents a data entity item. For example:

Forename | James | Richard
Surname  | Jones | Mayfair

Again, this isn’t an issue. The problem arises when I come to construct the table neatly. Using the builder pattern, I’ve got three classes: Table, Group and Row. They can be used like this:

$table = new Table($attribs);
$group = new Group(); // Nothing special about groups, they're just there for helping with presentation

$row = new Row();
$row->setTitle('Forename')
    ->setData(array('item1' => 'James', 'item2' => 'Richard'))

$row2 = new Row();
$row2->setTitle('Surname')
     ->setData(array('item1' => 'Jones', 'item2' => 'Mayfair'))

$group->addRow($row)
      ->addRow($row2);

$table->addGroup($group);

The above code snippet appears within a controllers’ action. The table object is then passed to the view and I’ve got a view helper that outputs to the table to my own specification.

The challenge that I’m facing however, is that I’ve ended up with a very messy ‘Results’ model. For example, I’ve got lots of:

$group->addRow($this->_resultsModel->getSurnameRow());

The ‘_resultsModel’ property is an object which contains a lot of methods that do:

public function getSurnameRow()
{
    $row = new Row();
    $row->setTitle('Surname');
    $row->setData($this->_getAssociateArrayOfSurnames());
    return $row;
}

Furthermore, the results object extends a results abstract class which contains accessor, setter and calculation methods for the raw data. Each of these ‘calculation’ methods returns an associative array of data which can be assigned to a row object. Both the results object and the abstracted class are both long and just seem disjointed.

So to summarise… I’ve ended up with one big results model that does all the calculations and returns all the row objects. Whilst it does work, I’m convinced there’s a better way of doing things. Should I be building the rows in the controller? Should I only be calling the calculations from the models? Does anyone have any experience abstracting stuff like this?

I apologise is this is a poor explanation. If anyone has any questions that I can field, let me know.

  • 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-06-08T09:32:11+00:00Added an answer on June 8, 2026 at 9:32 am

    First off, controllers shouldn’t have too much logic inside – controllers are there to handle input to models and forward results to output (view), not to calculate stuff.

    Second: Your results has so many other things to do, why does it have to deal with the table representation? Also, why does it have to have a lot of separate functions which differ only in a string?

    I guess I’d do something along with declarative arrays: that is, I’d collect a declarative array like this:

    $table_description = [
         'group1' => ['surname', 'firstname', 'whatever'],
         'group2' => ['other', 'rows', 'as', 'needed']
    ];
    

    and build something which parses this description and fills it up with actual data (using reflection if needed)

    The main issue is: form follows function, algorhythms follow data structure.

    If you have a data structure, which is divided into tables, groups and rows, then you are likely have an algorhythm which does the same.

    A second question is: where does the change likely occur? If the table scheme can change easily, put them into a “config” (a descriptor). If the rows’ formatting can change easily, make sure they’re self-formatting (or someone knows how to ask for a formatter, without knowing what the row actually contains)

    A good idea is to be able to fall back to defaults: that is, if most of the rows are constructed in a default way, then make sure you’re able to use a default method, like:

    class Row {
       public $formatter;
       private $data_assoc;
       private $title;
       public function __construct($title, $data, RowFormatter $formatter=NULL){
           if ($formatter == NULL){
              $this->formatter = DefaultFormatter::getInstance();   
           }
           /*set title, data_assoc...*/
       }
       public function setFormatter(RowFormatter $formatter){/*obvious*/}
       public function format(){
           return $this->formatter->format($this->data_assoc);
       }
    }
    

    Now, it seems, that your resultsModel has too many responsibilities, you have these prefix names (getSurnameRow) – why should the resultsModel know about rows at all? Also, associative arrays (maps) are pretty fine constructs, especially in PHP. Why isn’t a getData(‘Surname’) sufficient? Why isn’t the Row capable of constructing itself from a title and an associative data?

    If you want to do the same thing but with different properties, use an enum, or a string. If you need to be able to plug in things sometimes, use a factory, which looks up an index table based on property names, and falls back to a default implementation in case it isn’t an exception.

    $row = RowFactory::getRow('Surname');
    $row->setData($this->data['Surname']);
    

    Code duplication like this is fine as long as it’s two properties and simple orthogonality – like, getX, getY. But with an infinite amount of properties, I guess it’s just duplication.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a project where I use Zend Framework with Propel. I'm
I'm working on a project that is currently using the Zend Framework 1.7.6, however
Hi I'm currently working on some php - zend framework project on my osx
Currently I'm working on a project using Zend framework and the message notification dialog
I am currently working on a project developed using Zend Framework, based on the
I'm working on a project now that isn't based on Zend Framework, however I
I'm currently working on a build system in Phing that takes a Zend Framework
I am currently working with the Zend Framework and I use PHPEd as my
I am currently working on a API site based on Zend Framework. As ZF
I am a beginner working with Zend Framework, and currently having a small problem:

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.