• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Entities/Model - Validation and Calculation

#1
hi

i have this inputs
PHP Code:
$inputs = [
        'revenue' => 100,
        'cost' => 50,
        'tax' => '20',
    ]; 



and i need this outputs to save it on database
PHP Code:
$outputs = [
        'revenue' => 100,
        'cost' => 50,
        'tax' => 20,
        'EBITDA' => 50,
        'netProfit' => 40,
    ]; 

i'm using Entities and Model
1- where i must validate fileds?
2- where i must caculate data to set netProfit and EBITDA for save in database?
Reply

#2
1) One can place validation in the Entity so that validation is handled automatically, and is closely associated with the data it's validating (though, personally, because I find that in my typical usage, any given field frequently has several different conditions that sometimes do and sometimes don't apply, this started looking complicated... and I've resorted to having a separate 'validation class' that handles user input, which the Controller invokes separate to the Entity class (an approach that also has it's own inherent drawbacks)).

2) "Business rules" are typically supposed to be placed in the Model.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.