Organize the code for similar funcionallity


(russo89) #1

I have a funcionallity named “Tasks” divided with two parts. The part one with acess for all users, and the part two with similar funcionality, different layout and restricted for a specific users.
All of this in frontend. What the best way to organize my code?
Create one controller for the part one and other controller for the part two, and two folders for views.
like this:

> frontend/controllers

—TasksOneController.php
—TasksTwoController.php

> frontend/views

tasks-one
----index.php
----view.php
----etc…
tasks-two
----index.php
----view.php
----etc…

Or other structures for organize my code?
The “Tasks” is one example i have multiple cases of this.


(Alexander Makarov) #2

Depends on if these two functionalities are going to be developed differently. If they likely will, having a copy is fine. It won’t be a copy soon.

If these are going to stay the same forever a parent-controller with protected methods should be OK.


(russo89) #3

@samdark yes these are developed differently.
For you is not confused work with the example i refer?
Adding all time one “suffix” for the similar funcionallity?

another example is:

purchaseController.php
purchaseManagementController.php

views

 purchase
   index.php
   view.php

 purchase-management
   index.php
   view.php

(Alexander Makarov) #4

You can use modules for such separation.


(russo89) #5

Ok, so my code would look like this correct @samdark ?

 app
   -frontend
   ---controllers
   -----TaskOneController.php
   -----PurchaseController.php
   ---views
   -----task-one
   ------index.php
   ------view.php
   -----etc...

   ---modules     
   ----controllers
   -----TaskTwoController.php
   -----PurchaseManagementController.php
   ----views
   -----task-two
   ------index.php
   ------view.php
   -----etc...

(Alexander Makarov) #6

Yes. I’d get TaskOne into taskOne module and TaskTwo into taskTwo module.


(russo89) #7

why? I did not understand? why get taskOne in module?


(Alexander Makarov) #8

Because these are two separate groups of related functionality. You can, of course, keep one of these out of the module.