Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p>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?</p> <p>I guess I'd do something along with declarative arrays: that is, I'd collect a declarative array like this:</p> <pre><code>$table_description = [ 'group1' =&gt; ['surname', 'firstname', 'whatever'], 'group2' =&gt; ['other', 'rows', 'as', 'needed'] ]; </code></pre> <p>and build something which parses this description and fills it up with actual data (using reflection if needed)</p> <p>The main issue is: form follows function, algorhythms follow data structure. </p> <p>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. </p> <p>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)</p> <p>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:</p> <pre><code>class Row { public $formatter; private $data_assoc; private $title; public function __construct($title, $data, RowFormatter $formatter=NULL){ if ($formatter == NULL){ $this-&gt;formatter = DefaultFormatter::getInstance(); } /*set title, data_assoc...*/ } public function setFormatter(RowFormatter $formatter){/*obvious*/} public function format(){ return $this-&gt;formatter-&gt;format($this-&gt;data_assoc); } } </code></pre> <p>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? </p> <p>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.</p> <pre><code>$row = RowFactory::getRow('Surname'); $row-&gt;setData($this-&gt;data['Surname']); </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload