russo89
(russo89)
July 12, 2019, 12:37am
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.
samdark
(Alexander Makarov)
July 12, 2019, 12:18pm
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
(russo89)
July 12, 2019, 12:44pm
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
samdark
(Alexander Makarov)
July 12, 2019, 11:34pm
4
You can use modules for such separation.
russo89
(russo89)
July 13, 2019, 9:05pm
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...
samdark
(Alexander Makarov)
July 14, 2019, 11:55am
6
Yes. I’d get TaskOne into taskOne module and TaskTwo into taskTwo module.
russo89
(russo89)
July 14, 2019, 12:37pm
7
why? I did not understand? why get taskOne in module?
samdark
(Alexander Makarov)
July 14, 2019, 11:30pm
8
Because these are two separate groups of related functionality. You can, of course, keep one of these out of the module.