Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax heavy application question and OO design questions
    primarykey
    data
    text
    <p>I have a enterprise webapp that is extremely ajax heavy, all data goes though some sort of ajax, so is saving, updating deleting etc. Modeled after the MVC paradigm</p> <p>The site is mostly compromised of three parts</p> <p><strong>Interface page</strong> An interface page only contains the interface and all the js that goes with it, no data processing of any kind. All data is requested after the interface has loaded. All data is transmitted and received in a common interchange format.(More below) eg. edit_inventory.php or list_inventory.php</p> <p><strong>Backend Page</strong> A backend page that processes data when commands are received kinda like APIs that you see on other webapps, it basically have a giant switch statement of all the commands it accepts. eg. ajax_inventory.php</p> <p><strong>Classes Page</strong> A page with a single class that handles a single object, eg item, invoice, account etc. They currently handle only database connections, getting data and saving data. It is also responsible for error checking and taking care of foreign key links/cascade data.</p> <p>Copying from a typical CMS, a set of classes, interface and backends are called components.</p> <pre><code>root &gt;comp &gt;inventory &gt;class_inventory.php &gt;ajax_inventory.php &gt;edit_inventory.php &gt;list_inventory.php &gt;ajax_inventorymerge.php &gt;edit_inventorymerge.php &gt;account </code></pre> <p>After a while, I noticed this method or idea have generated a lot of files, current at 400+ files just for interfaces and backends. The 400+ pages are quite unique in their own respects, most are complex CRUD interfaces for billing, inventory, reporting, misc data.</p> <hr> <p>The questions, I am looking for answers that are commonly used.</p> <ol> <li><p>Is this a good pattern, can it be improved?</p></li> <li><p>Should objects and classes such as "Product" responsible for formatting the data into the common interchange format as mentioned earlier?</p></li> <li><p>Should objects allow unfiltered access to their data or only filtered access? Unfiltered access also meant that there must be lots of filtering to be done at the backend level. Filtering is mostly getting rid of unwanted data(waste of bandwidth) or metadata. However, sometimes it might be data that the user should not see(Permission related). Filtering is mostly done on the key-values pair(form_data)</p></li> <li><p>Since there are multiple data forms outputted by an object from html(form_html), messages(msg), key-value pair(form_data) etc. How would one best request the data in one whole, rather than $a->getData(), $a->getMsg, $a->getStuff? Another interchange format? or just use the common interchange format as mentioned earlier?</p></li> </ol> <p>Common Interchange format(in json)</p> <pre><code>{"msg":"Sucess", "form_data":{ "id":100, "product_code":"BLA", "size":"3" }, "form_html":{ "list":"&lt;\/li&gt;&lt;\/ul&gt;" }, "script":"alert('Some stuff');" } </code></pre>
    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.
    1. COthis somehow sounds like a premature implementation of codeigniter, so it is common, only that codeigniter puts big packs of controlling into single controller classes so that you have controller capable of handling multiple actions and thus resulting in less files. Also codeigniter just has one index file that handles everything but by the right uri encoding it dispatches the calls to the according classes and their according functions to handle the incoming requests. the models are just for representation of stored data and the views for showing data to the user, eg the interface itself.
      singulars
    2. COActually sounds a lot closer to MVC or MVP than most PHP frameworks come. 400 files however forebode maintenance issues. Not sure about the mentioned interchange format or what could be unified. Please add a concrete example of one of those objects and the transferred data, maybe expand on what data might require filtering (I assume it's not permission related).
      singulars
    3. COyes, it looks like MVC but i dont understand why you have more than 3 files.. when you could only have something like: class_inventory.php, view_inventory.php and controller_inventory.php. If you are using ajax that only means that the controller must tell the View to produce the JSON code instead of HTML..
      singulars
 

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